As part of WinUX update 2.3, improvements have been made to the WindowHelper to make it easier to create and manage secondary windows for your UWP application.

If you’ve not yet looked at the WinUX project, you can explore the code on GitHub or get using it via our NuGet packages!

What is a multi-window app?

Most Windows apps are single window experiences and this is noticed most on Windows mobile devices where only a single app can run at a time. However, it is possible to create multi-window experiences with UWP where your main app’s window can create a new window for you and this feature has been available in Windows APIs since Windows 8.1. This post on MSDN provides you with more information on multi-window experiences.

What’s new in multi-window support?

The WindowHelper improvements allow you to create a new window for a page, similar to navigating using the NavigationService, and is a simple one line of code.

There are 8 variations available, 4 using the Type for the page and 4 using the type’s name as a string which is particularly useful if you’re wanting to navigate to a page in a library you’re not directly referencing but is referenced by your main app.

The variations allow you to provide a preferred size for the new window and allow you to pass a parameter to the page as part of the navigation arguments.

When this method is called it performs two things, creating and showing the new window and registering WinUX services for your new view which you can take advantage of if needed. These services are particularly useful if you’re creating an MVVM application and want to access the navigation service for your new window, for example. The services that are currently registered are:

CoreDispatcher

The core dispatcher is acquired when the view is created and a reference to it stored for you to use whenever needed. You’ll be able to get the instance for the view you’re calling from by passing the view’s int identifier to the ViewCoreDispatcherManager.Current.Get(int viewId) method.

NavigationService

The navigation service is a feature available in WinUX that makes app page navigation easier. It’s a core feature for windows and as such, we create one of these for you too. Again, you’ll be able to get the instance for the view you’re calling from by passing the view’s int identifier to the ViewNavigationServiceManager.Current.Get(int viewId) method.

MessageDialogHelper

Handling message dialogs is made easier in WinUX using the MessageDialogHelper class. It allows you to queue up detailed message dialogs without the developer having to worry about making sure it won’t crash their application because it’s being called from the wrong thread! These are particularly useful so we will create an instance of one of these for every window you create so you can open dialogs on that window. The instance can be obtained by passing the view’s int identifier to the ViewMessageDialogManager.Current.Get(int viewId) method.

As well as these, we provide you with a base ViewServiceManager which you can use to register your own view specific services where required.

Extended support for MvvmLight developers

If you use MvvmLight, WinUX update 2.3 features a new package created just for you with an MVVM Page base class, PageBase, and associated view model base class, PageBaseViewModel.

PageBase

PageBase is a basic extension to the Page class which provides support for XAML and code based adaptive visual states, page loading and navigation which are also surfaced up to the associated view model when using a view model that inherits the PageBaseViewModel. The PageBase also has a reference to the type of device that the application is running on, which is particularly useful for device based visual states, and the int identifier of the view it was created for.

CoreViewModelBase

CoreViewModelBase is the view model base class which sits on top of MvvmLight’s ViewModelBase class which provides the extended support for multi-window experiences by providing you with the int identifier for the view as well as properties for the CoreDispatcher, MessageDialogHelper and NavigationService associated with the view. Like the PageBase, we also provide the type of device that the application is running on just incase you need to do any device specific logic in your view models.

PageBaseViewModel

PageBaseViewModel is the view model base class which should always be used in conjunction with PageBase. It has the method calls in it that allow you to perform actions in your view-model when the page has loaded, the size has changed, the adaptive state has been modified or a navigation event has occurred.

If you have any feedback, found an issue or if you’re interested in contributing towards WinUX, head over to the GitHub repo for the project!

Author James Croft

James is a senior software developer for Black Marble and Microsoft MVP in Windows Development with over 6 years of experience developing applications for the Windows platform. James’s passion for learning new technologies gives him the opportunities to expose them to the wider community through tutorials, lessons learned and best practices through his online blog site, personal YouTube channel, and local communities through talks at events, schools and universities.

More posts by James Croft

Leave a comment