Question

I am confused about two way of navigating from one page to another in Windows 8.

First one :-

using a frame that is defined initially in App.Xaml.cs class like this.

 public static Frame RootFrame;

 protected override void OnLaunched(LaunchActivatedEventArgs args)
 {
      RootFrame = Window.Current.Content as Frame;
 }

navigating through it like..

App.RootFrame.Navigate(typeof(Page1));

Second one :- It is simple way of navigation like..

this.Frame.Navigate(typeof(page1));

question :- Is there any difference in these two types , if yes please let me know.

Was it helpful?

Solution

These are the same method, in fact operating on the same object. Your application object creates a Frame object that hosts pages (in the basic app template, when the application is first launched, note that if rootFrame is null, it news up a Frame and sets it to Window.Current.Context).

From that point forward, you are using navigation functions of that same Frame object. When you navigate to Page1, the Frame sets the Page1.Frame property to itself, so in Page1, this.Frame points at the same object as App.RootFrame (essentially a "parent" link).

So, Window.Current.Content hosts a Frame object, and that object hosts Pages. Each Page has a pointer back to that Frame which they can use to command that Frame to Navigate to other Pages.

Note that Window.Current.Content itself is a SETTABLE UiElement. That means it could technically host UI other than a Frame. This could be used to (for example) make some chrome that itself hosted a Frame which was the actual content of your app (like the HTML iFrames of old). I did this in one case in order to create a developer console that was easily invokable/usable from every page of my application (because it existed ABOVE the level of the frame hosting the individual pages).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top