Sean
Sean

Reputation: 2667

UWP model clarification

In the following Microsoft reference page:

https://msdn.microsoft.com/en-us/library/windows/apps/mt187344.aspx

..they identify two types of navigation models for UWP apps, single-page (recommended), and the multi-page. However, the terminology they use is quite ambiguous (documents?), and contradictory. Can someone please explain to me precisely the distinction between single-page and multi-page apps? Below is the excerpt that doesn't make much sense:

"UWP apps typically use a single-page navigation model. A single-page navigation model uses a single page to maintain app context and load additional data and content into a central frame, as needed. You still split your application into multiple files, but instead of moving from page to page, your app loads other documents into the main page frame. Because your app's main page is never unloaded, code and data is never unloaded, which makes it easier to manage state, and provide smoother transition animations between pages. We recommend using the single-page navigation model."

Upvotes: 1

Views: 159

Answers (1)

Decade Moon
Decade Moon

Reputation: 34306

I read that page too and am somewhat confused by what they mean exactly. Here's my thoughts:

  • When I say "page" I mean a Windows.UI.Xaml.Controls.Page.

  • They explain the single-page model as "uses a single page" but then goes on to say "provide smoother transition animations between pages". Huh? I thought there was only a single page, so why would you be navigating between multiple pages? Also it mentions that the single-page model primarily relies on various methods of the Frame class like Navigate, GoBack and GoForward, but you wouldn't be doing this (or even using a Frame) at all if you only ever had a single page.

  • They also say that the single-page model is the recommended approach. Really? Unless the app is very simple with only a single screen, then I don't believe that most apps would use this navigation model. All project templates create a Frame for your in anticipation of you writing a multi-page app.
  • They don't explain what a "document" is. To me, a document is something like a text document (for a text-editor or word processing app) or an image (for an image editor app), but not all apps are document-based apps (like the Facebook app, for example).

For most apps, I would recommend the following navigation model (whatever that ends up being called):

  • When your app is launched, set the Content of the Window to a Frame instance. This is what the project templates do for you already.
  • Each screen for your app can be a separate page, and use the navigation methods of the frame to navigate between each page. The frame can be accessed from within a page by the Page.Frame property.

Some apps have a hamburger menu a-la the SplitView control. In that case, the SplitView would be the content of the Window and the frame would be inside the SplitView instead.

Of course, you can do whatever you like that fits the needs of your app.

You don't typically have a frame within a page unless you have some very custom navigation structure.

Upvotes: 2

Related Questions