Reputation: 9242
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.
Upvotes: 1
Views: 97
Reputation: 1962
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 Page
s. Each Page
has a pointer back to that Frame
which they can use to command that Frame
to Navigate to other Page
s.
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).
Upvotes: 2