Wednesday, 29 January 2014

Prism for the Windows Runtime Templates for Windows 8.1 updated

I’ve updated the Prism for the Windows Runtime templates for Windows 8.1 on the Visual Studio Gallery. v1.1 of the templates introduces the following changes:

  1. The UserControl View item template now sets Prism’s AutoWireViewModel property to true.
  2. The Page View item template no longer sets the IsEnabled property on the back button.
  3. The MainPage class, created by both the Prism App and Prism App using Unity project templates, no longer sets the IsEnabled property on the back button.

For more info and to download the templates see Prism Templates.

Monday, 27 January 2014

Prism for the Windows Runtime now supports extended splash screens

One of the new features of Prism for the Windows Runtime for Windows 8.1 is the introduction of support for displaying an extended splash screen that imitates the splash screen displayed by Windows. If an app needs more time to prepare its UI or load network data, you can use an extended splash screen to display a message to the user as the app completes those tasks. For more info about extended splash screens, see How to extend the splash screen and Guidelines for splash screens.

Prism for the Windows Runtime defines an ExtendedSplashScreenFactory property in the MvvmAppBase class. The MvvmAppBase class will check this property during app startup, and if it’s defined it will show the extended splash screen. Therefore, the property should be set to a delegate that returns the app’s extended splash screen.

this.ExtendedSplashScreenFactory = (splashscreen) => new ExtendedSplashScreen(splashscreen);
When an app is launched the system passes splash screen information to the app’s launch activation event handler. This information is used to correctly position the image on the extended splash screen page over the splash screen image displayed by Windows. In a Prism app the app’s launch activation event handler is in the OnLaunched method in the MvvmAppBase class. This method in turn calls the InitializeFrameAsync method in the same class, passing in the launch activation event arguments.
rootFrame = new Frame();
if (ExtendedSplashScreenFactory != null)
    Page extendedSplashScreen = this.ExtendedSplashScreenFactory.Invoke(args.SplashScreen);
    rootFrame.Content = extendedSplashScreen;

Inside the InitializeFrameAsync method, if the ExtendedSplashScreenFactory property is defined the factory will create the extended splash screen page and place it in the Frame for display, before continuing with further initialization. This approach allows the extended splash screen to be displayed without performing a navigation operation, ensuring that it will not form part of the app's navigation history.

For more information, including how to create the extended splash screen, how to correctly position the extended splashscreen, and a full downloadable code example, see Extended splash screen Quickstart for Windows Store apps using C#, XAML, and Prism.

Monday, 20 January 2014

First drop of Windows Azure Media Services Guidance

The first drop of the Windows Azure Media Services guidance can be found on codeplex. To compile the code you’ll need Windows 8.1, Visual Studio 2013, and the Windows Azure SDK. Obviously the usual caveats apply to the download, as it’s not final released code yet.

The project is about producing guidance for using Windows Azure Media Services in conjunction with a Content Management System (CMS) for providing an on-demand video service. The project will show how to link Windows Azure Media Services assets to a CMS entry as well as how to ingest, encode, publish, and consume videos on the following platforms:

  • Windows 8.1
  • Windows Phone 8
  • HTML 5
  • iOS 5
  • Android Jelly Beans 4.1 (API Level 16)

Thursday, 16 January 2014

Adding items to the Settings pane using Prism for the Windows Runtime for Windows 8.1

Previously I’ve written about using Prism for the Windows Runtime for Windows 8.0 to add an item to the Settings pane. The item was a privacy policy as an example. Prism’s SettingsCharmActionItem class was used to define a Settings pane item and the action that was performed when the item is selected. When the privacy policy was selected Prism’s FlyoutService was used to display the PrivacyPolicyFlyout view.

In Prism for Windows 8.1 the SettingsCharmActionItem and FlyoutService classes have been deprecated. Therefore the purpose of this blog post is to show how to add a privacy policy to an app using Prism for Windows 8.1.

If an app has the ability to transmit data, it must contain a privacy policy. For more info see Windows 8 app certification requirements. While the example app does not transmit data, a privacy policy makes a suitable example to showcase how to add an item to the Settings pane using Prism for the Windows Runtime, When the user invokes the Settings pane from any page of the app they will see an item named Privacy Policy. Selecting this item will display a Flyout that displays the app’s privacy policy.


Creating the Flyout view

A SettingsFlyout view is required to display the app’s privacy policy. However, it does not require an associated view model as the view does not need to bind to any data in a view model, instead displaying embedded text. Please note that in a real app a view model would most likely be required in order to handle user acknowledgement of the privacy policy, and to obtain the localized version of the privacy policy from a resource file.

The sample app defines a SettingsFlyout named PrivacyPolicyFlyout which simply includes a TextBlock to display the text of the privacy policy.

    Background="{StaticResource SettingsFlyoutBackgroundThemeBrush}"
    Title="Privacy Policy"
    <StackPanel x:Name="FlyoutContent">
        <TextBlock Style="{StaticResource BasicTextStyle}"
                   Text="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." 

Adding an item to the Settings pane

The PrivacyPolicyFlyout can be displayed by the Settings pane by overriding the GetSettingsCommands method from the MvvmAppBase class in your App class and adding code to add the item to the Settings pane.

protected override IList<SettingsCommand> GetSettingsCommands()
    var settingsCommands = new List<SettingsCommand>();
    settingsCommands.Add(new SettingsCommand(Guid.NewGuid().ToString(), "Privacy Policy", (c) => new PrivacyPolicyFlyout().Show()));
    return settingsCommands;

In this method a new SettingsCommand is created and added to a list of SettingsCommand. The SettingsCommand takes three parameters – a unique id, the text to show in the Settings pane, and the event handler that is called when the user selects the command in the Settings pane. So here, when the user selects the Privacy Policy text in the Settings pane, the PrivacyPolicyFlyout will be displayed by invoking the Show method of the SettingsFlyout class.


In this blog post I’ve extended the sample app so that the Settings pane contains a Privacy Policy item. Prism’s GetSettingsCommands method is overriden to add a SettingsCommand to the Settings pane. When the privacy policy text is selected the Show method of the SettingsFlyout class is used to display the PrivacyPolicyFlyout.

The sample app can be downloaded here.

Friday, 3 January 2014

Prism for the Windows Runtime Templates for Windows 8.1

In order to make consuming Prism for the Windows Runtime for Windows 8.1 easier I’ve created a set of Visual Studio project and item templates. These templates can be downloaded from the Visual Studio Gallery. Please note that the templates are not a patterns & practices release. They’ve been created in my spare time, and if you have any issues with them, or suggestions for future developments, you should report them to me through the Contact page on my blog.

For more info about the templates see Prism Templates. To download the templates visit the Visual Studio Gallery.

Please note that the templates for Prism for the Windows Runtime for Windows 8.0 are also still available on the Visual Studio Gallery.