Sunday, July 2, 2017

UWP Tip #1 - Build Your First App with Windows Template Studio

Welcome to the Tip #1 here on UWP Tips!Do you have an idea for an relatively simple app but just don't have the time to get it off the ground? Maybe you have a web site or blog, and you would like to add an app that surfaces the existing web UI. Even the simplest of apps requires a great deal of infrastructure code be built up front, right?

Windows Template Studio

After installing the extension, select the new project type for Windows Template Studio (Universal Windows) found under Windows Universal. This will start a wizard-style experience to select the frameworks, pages and features to be added to your application.

The Wizard

I elected to create a Navigation Pane project using MVVMLight instead of the code-behind model for my app. I also added three Web View pages for my three blogs, named UWPTips, WPFTips and MorningDew.

Upon completing the wizard, the solution is loaded in Visual Studio 2017. Each view, in addition to the Main and Shell views, is generated along with a corresponding ViewModel.

Each of my Web View ViewModels has a constant defined for the initial web page to load into the View.

I made one additional change to the generated project. In the PopulateNavItems() method of ShellViewModel, I updated the symbols used as icons in the left navigation bar for each page. By default, each was using Symbol.Document. I changed this to make each page's symbol unique and more identifiable.

The items in the Windows.UI.Xaml.Controls.Symbol enum correspond to glyphs from the Segoe MDL2 Assets font. More information is available on Microsoft Docs.

Here is a look at the app running on Windows 10 with the Creators Update. The left navigation hamburger menu has been expanded to reveal the page names, otherwise only the glyph icons appear. The WPFTips page has rendered the current content of www.wpf.tips.

The status bar area of each web view page contains basic navigation buttons for back, forward and reload plus a button to open the current page in your default browser. These web views are hosted in an embedded Microsoft Edge browser control. While an app that hosts three blog sites may not be a worthy addition to the Store, it could be made more useful by displaying individual blog posts in a 'reading mode' with sidebars, headers and footers from the sites hidden. This application style might be even more useful hosting pages containing document repositories or other online libraries.