Prism for Windows Runtime

As Blaine Wastell posted, we are about to release the patterns & practices guidance for building Windows Store business apps. You may be thinking… “What is a business app?” and “How is a business app different than any other app?”. Well the simple answer is that a “business” app is expected to be well architected, maintainable, testable, and have high quality. Business apps may differ from simple content consumption apps in many ways. Business apps are more likely to need data validation. There is probably more state data that needs to survive suspension and termination. Also, it is more likely that business apps will be developed by teams of developers that want a decoupled architecture and a codebase that is maintainable and testable.

Basically, if you are interested in improving the quality and maintainability of your Windows Store apps, I recommend taking a look at this guidance.

You can get the latest source on CodePlex.

This post is part 1 of a series that walks you through how to use the Prism for Windows Runtime library to create a Windows Store app. The Prism library will not only make your apps more testable and maintainable, I believe it will also make it easier to create Windows Store apps.

Creating a Hello World app using Prism for Windows Runtime

  1. Create a new C#-based Windows Store app named HelloWorld using the Blank App (XAML) Visual Studio project template.
  2. Add a reference to the Microsoft.Practices.Prism.StoreApps library.
  3. Add a folder named “Views” to the root folder of the Windows Store app project.
    This app will use the FrameNavigationService class, provided by the Microsoft.Practices.Prism.StoreApps library, to navigate. The FrameNavigationService class’s default convention is to locate pages in the "Views" namespace of the Windows Store app project. When the Navigate method of the FrameNavigationService class is called with a page token parameter, "Page" is appended to the page token. For example, if the Navigate method was called with "Customer" as the page token, the FrameNavigationService would look for a page named "CustomerPage" in the "Views" namespace.
  4. Add a new Blank Page named “StartPage” to the Views folder.
  5. Add a TextBlock control to the page’s Grid control.    
    <TextBlock Text="Hello World!!!" Style="{StaticResource HeaderTextStyle}" />
  6. Delete all of the contents of the App.xaml.cs file. This boilerplate functionality is now provided by the MvvmAppBase class.
  7. Add the following code to the App.xaml.cs file.
    using Microsoft.Practices.Prism.StoreApps;
    sealed partial class App : MvvmAppBase
        public App()
  8. Update the App.xaml file so that the App class derives from the MvvmAppBase class rather than the Application class.
    <Infrastructure:MvvmAppBase xmlns:Infrastructure="using:Microsoft.Practices.Prism.StoreApps">
  9. Add code to the App class to navigate to the StartPage.

    The MvvmAppBase class provides several virtual methods that you can override to customize its behavior. However, MvvmAppBase provides the OnLaunchApplication abstract method for which you must provide an override. This method specifies what your app will do when it’s launched.

    protected override void OnLaunchApplication(LaunchActivatedEventArgs args)
        NavigationService.Navigate("Start", null);

    The MvvmAppBase has a NavigationService property that exposes the FrameNavigationService.
  10. Run the app. When the app runs you will see the StartPage with the “Hello World!!!” TextBlock.


Next let’s take a look at how to associate a view model to the StartPage view in my next post: Creating a basic implementation of the MVVM pattern.

Comments (4)

  1. Suresh says:

    Thanks for such a great framework. I agree on that if we interested in improving the quality and maintainability of your Windows Store apps, we should follow this guidance.  

  2. Kyle says:

    Could you put this series articles into Microsoft Virtual Academy? Thank you for your hard work.

  3. @Kyle: Thanks for the suggestion. I'll look into MVA. May need to record some videos at least.

  4. RobReno says:

    Hi Francis, do you have the code for this Hello World that is current. I am following the steps above but getting a number of errors I would appreciate some help with.