Other Ways to Use Frame

Not every app needs to follow the pattern of a Window hosting a Frame that hosts Page(s). A Window’s content doesn’t have to be a Frame, and you can embed Frames anywhere UIElements can go. We can demonstrate this by modifying a Hub App project to set the Window’s Content to a custom Grid subclass that we create. Imagine this is called RootGrid, and it must be constructed with a Frame that it wants to dynamically add to its Children collection. It would be used in App.xaml.cs as follows:

// Instead of Window.Current.Content = rootFrame: Window.Current.Content = new RootGrid(rootFrame);

RootGrid can be added to the project as a pair of XAML and code-behind, shown in Listings 7.3 and 7.4.

Get Universal Windows® Apps with XAML and C# Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.