Navigation Service and Instances

As you know, you cannot Navigate to an instance directly, you have to navigate to an uri. So, Do you have to navigate to a instance that indeed you want to set several properties and actions before  navigate?

Well I realize out that every page has a Content, In this case I left the LayoutRoot, because the thing I want instanced is not really the page, is the Content of the page. So the steps to Navigate to a instanced control are:

  1. Create a Page named EmptyPage.xaml
  2. Create your Super User Control with all the features you want.
  3. Add the following navigation code in an event click or a command (for instance):
NavigatedEventHandler InstanceNavigation = null;
InstanceNavigation = (sn, en) =>
if (en.Content as EmptyPage != null)
WindowsPhoneControl1 wp = new WindowsPhoneControl1();
(en.Content as EmptyPage).LayoutRoot.Children.Add(wp);

DispatcherTimer dt = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(10) };

dt.Tick += (st, et) =>
wp.Text1.Text = Count.ToString();

if(Count > 1000)

NavigationService.Navigated -= InstanceNavigation;

NavigationService.Navigated += InstanceNavigation;
NavigationService.Navigate(new Uri("/EmptyPage.xaml", UriKind.Relative));

That’s all, now when you navigate to the EmptyPage you are really navigating to a processed instanced user control.

The main reasong I did this instead of adding  the control over the current page is due to performance reasons, Is pretty much in a clean page that in over the current page.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s