Upgrading Windows Phone Silverlight 8.0 App to Windows Phone Silverlight 8.1

    We continue the series of articles on updating Windows Phone 8.0 applications to version 8.1. Today we’ll look at the new features of Silverlight 8.1 and the upgrade process for Windows Phone Silverlight 8.0 applications to version 8.1.

    Short review

    The new version of Windows Phone Silverlight 8.1 provides mobile application developers with access to Windows Phone 8.1 WinRT features without significantly changing the code for an existing Silverlight application.

    Silverlight 8.1 is a continuation of technology for Silverlight developers.

    Upgrading an application to Silverlight 8.1 is very simple using the built-in tool in Visual Studio 2013:

    Please note that Silverlight 8.1 applications only work on Windows Phone 8.1 devices. If you want to maintain the application on previous versions of operating systems, it is recommended that the store distribute the old version of the application on Silverlight 8.0 as well.

    If you are just starting development for Windows Phone and would like to have a version of the application for your PC, it is recommended that you begin development on the new Windows Phone 8.1 ( WinRT or WinJS ), which provide the ability to create universal applications for phones, tablets and PCs. Unfortunately, an application on Silverlight 8.1 cannot be expanded to a universal one.

    How to choose the appropriate technology for developing your mobile application can be read here .

    What's New in Windows Phone Silverlight 8.1

    Many of the tools and APIs available for Silverlight 8.0 applications will also be available for Silverlight 8.1. Some differences in use are described in the next article .

    Listed below are some of the new features available for Silverlight 8.1 applications:
    • API extension, i.e. in addition to the WinRT APIs available in Silverlight 8.0, when migrating to Silverlight 8.1, the XAML 8.1 WinRT APIs will also become available;
    • Bonuses for graphics, text, etc. with D2D / DWrite / WIC / ...;
    • Silverlight 8.1 application will be able to act as a photo provider if necessary;
    • Updated “seamless” integration of VoIP service for audio-video calls over the Internet;

    Features available only for Windows Phone 8.1 applications, but also supported for Silverlight 8.1 applications:
    • New tools for testing the application;
    • Work with files;
    • Expansion of storage, backup, data recovery capabilities;
    • SD card support;
    • Sharing data between applications;
    • Tiles, event indicators, push notifications using the new Windows Push Notification Service (WNS);
    • Performing tasks and transferring data in the background;
    • Creation of network applications and the possibility of a single authorization on different services for users, using the new ability to store user authentication data;
    • Support for Bluetooth and WiFi Direct services, device discovery;
    • Update NFC payment instruments;
    • Intelligent input panel;
    • Sending letters and attachments;
    • Access to contacts and calendar;
    • Sensors for the position of the device in space;
    • Geographical location and geolocation;
    • Possibilities of working with photos, video, audio materials, saving, editing media content;

    A more detailed list and information about new features in Silverlight 8.1 are located on MSDN .

    How to upgrade an application from Windows Phone Silverlight 8.0 to Silverlight 8.1

    Consider the process of upgrading a Windows Phone Silverlight 8.0 application to 8.1 using the following example. Take the content application - “Cookbook”. It contains recipes sorted by country, each recipe consists of several pages: description, ingredients, photos. The application, in addition to displaying recipes, allows you to add photos of your own dishes and fix the recipe you like on the phone’s start screen.

    What you need for development:

    The process of updating Silverlight 8.0 application to 8.1:
    1. Do not forget to backup the portable application;
    2. Open the solution (.sln extension file) in Visual Studio 2013;
    3. Right-click on the context menu:
    4. Then click Yes:
    5. We get the solution in the Windows Phone Silverlight 8.1 browser:

    The main icon is in place, but it seems that images for the comfortable operation of the updated application now require much more.

    Learn more about the image requirements of Windows Phone Silverlight 8.1 applications in this article .

    We solve this problem simply by creating the necessary images and placing them in the Assets folder of the current application:

    Testing the ported Windows Phone Silverlight 8.1 application

    Run the emulator and open the application:
    • List of countries - List of recipes for each country - Recipe:
    • We simulate the situation of switching to another application from the current recipe, for example, to “Messages”:
    • We return to the application through the menu:
    • We get an error in the behavior of the application.

    The application did not open a new copy of the previously launched application, as it happened in Silverlight 8.0, in the case of returning to work with the application, the following happened: the screen blinked, the application redirected the user to the start page and stopped displaying any data, and the launch of the current copy of the application was expected , in the same place where it was interrupted.

    This behavior is associated with a change in the life cycle of a Windows Phone application. Let's try to fix it.

    Correcting bugs in a ported application

    1. In the solution explorer, open the app.xaml.cs file:

      Check the FAR - Fast app resume (quick resume) feature, which allows you to open the copy of the application that is in memory.

      Here in the Phone Application Initialization area, we see that the FAR processing template code is available and everything should work correctly:
      #region Phone application initialization
              // Avoid double-initialization
              private bool phoneApplicationInitialized = false;
              // Do not add any additional code to this method
              private void InitializePhoneApplication()
                  if (phoneApplicationInitialized)
                  // Create the frame but don't set it as RootVisual yet; this allows the splash
                  // screen to remain active until the application is ready to render.
                  RootFrame = new TransitionFrame();
                  RootFrame.Navigated += CompleteInitializePhoneApplication;
                  // Handle navigation failures
                  RootFrame.NavigationFailed += RootFrame_NavigationFailed;
                  // Handle reset requests for clearing the backstack
                  RootFrame.Navigated += CheckForResetNavigation;
                  // Ensure we don't initialize again
                  phoneApplicationInitialized = true;
              // Do not add any additional code to this method
              private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
                  // Set the root visual to allow the application to render
                  if (RootVisual != RootFrame)
                      RootVisual = RootFrame;
                  // Remove this handler since it is no longer needed
                  RootFrame.Navigated -= CompleteInitializePhoneApplication;
              private void CheckForResetNavigation(object sender, NavigationEventArgs e)
                  // If the app has received a 'reset' navigation, then we need to check
                  // on the next navigation to see if the page stack should be reset
                  if (e.NavigationMode == NavigationMode.Reset)
                      RootFrame.Navigated += ClearBackStackAfterReset;
              private void ClearBackStackAfterReset(object sender, NavigationEventArgs e)
                  // Unregister the event so it doesn't get called again
                  RootFrame.Navigated -= ClearBackStackAfterReset;
                  // Only clear the stack for 'new' (forward) and 'refresh' navigations
                  if (e.NavigationMode != NavigationMode.New && e.NavigationMode != NavigationMode.Refresh)
                  // For UI consistency, clear the entire page stack
                  while (RootFrame.RemoveBackEntry() != null)
                      ; // do nothing

      Check what happens with the display of data.
    2. Open MainPage.xaml.cs and observe the following:
      In the OnNavigatedTo method, the condition is checked whether the list of recipes is loaded now:
       protected override void OnNavigatedTo(…)
                  if (!App.Recipes.IsLoaded)
                      pi = new Microsoft.Phone.Shell.ProgressIndicator();
                      pi.IsIndeterminate = true;
                      pi.Text = "Loading data, please wait...";
                      pi.IsVisible = true;
                      Microsoft.Phone.Shell.SystemTray.SetIsVisible(this, true);
                      Microsoft.Phone.Shell.SystemTray.SetProgressIndicator(this, pi);
                      App.Recipes.RecipesLoaded += Recipes_RecipesLoaded;

      When you call the same application again, the method determines the list of recipes as already loaded and does not perform the actions specified by this condition.
      Add an alternative condition processing option:
                      if (e.NavigationMode == NavigationMode.New)
                          lstGroups.DataContext = App.Recipes;

      We check to make sure that everything works correctly.
    3. Errors were detected when opening files that are responsible for the application interface.
      We open any file, for example, MainPage.xaml, and we get the lack of display of elements in the designer:

      To solve the problem with the form designer, you need to pay attention to the following error:
      The member “Instance” is not recognized or is not accessible.
      The error means that the property is no longer supported.

      Further in the text of the file we find the line:

      We bring it to this form:

      The visual constructor is fine:

    The compiler also reports errors related to the absence of toolkit elements: The

    new WinRT platform includes both old controls and many new ones. Therefore, the Windows Phone Toolkit library is no longer needed for mobile applications. Comment on or replace them with new analogues.

    Please note when updating the application for differences in namespace and classes.

    For example, in this application we used the ListView class, which no longer exists in Windows Phone Silverlight 8.1 and we replaced it with a ListBox in the application.
    The LongListSelector class is also no longer supported, and we use the option to replace it:
    It was:

    It became:

    Add new features

    One of the new features for Silverlight 8.1 is the ability to exchange data with other applications, including images.

    Our application can create and store photos of the cooked dish, try to teach him to "share" using the new features of the API:
    1. In the Solution Explorer, open the RecipeDetailPage.xaml file:

    2. For the Application Bar element, add a new “Share” button:
      • Using the Properties window for the ApplicationBar, find the Buttons button collection, add the AppBarButton button, select the standard icon icon = share.png and specify its name text = ”share”:
      • Create and write a handler for the “Share” button:
        private void ShareButton_Click(object sender, EventArgs e)
      • { if (item.UserImages == null || item.UserImages.Count == 0) { MessageBox.Show("You must take a picture first!"); } else { DataTransferManager.ShowShareUI(); } }

    3. In the OnNavigatedTo method, add the DataRequested event:
      protected async override void OnNavigatedTo(NavigationEventArgs e)
         DataTransferManager.GetForCurrentView().DataRequested += RecipeDetailPage_DataRequested;

      Create a function to handle this event:
      async void RecipeDetailPage_DataRequested (DataTransferManager sender, DataRequestedEventArgs args)
    4. Create and override the OnNavigatedFrom method:
      protected override void OnNavigatedFrom(NavigationEventArgs e)
          DataTransferManager.GetForCurrentView().DataRequested -= RecipeDetailPage_DataRequested;
    5. Add the code to the RecipeDetailPage_DataRequested function to handle the DataRequested event:
                  DataRequest request = args.Request;
                  var deferral = args.Request.GetDeferral();
                      Uri photoFileUri = new Uri("ms-appdata:///local/" + item.UserImages[0]);
                      var photoFile = await StorageFile.GetFileFromApplicationUriAsync(photoFileUri);
                      request.Data.Properties.Title = "I've been baking!";
                      request.Data.Properties.Description = "This was my attempt at making " + item.ShortTitle;
                      // It's recommended to use both SetBitmap and SetStorageItems for sharing a single image
                      // since the target app may only support one or the other.
                      List imageItems = new List();
                      RandomAccessStreamReference imageStreamRef = RandomAccessStreamReference.CreateFromFile(photoFile);
                      // It is recommended that you always add a thumbnail image any time you're sharing an image
                      request.Data.Properties.Thumbnail = imageStreamRef;
                      // Set Text to share for those targets that can't accept images
                      request.Data.SetText("I just made " + item.ShortTitle + " from Contoso Cookbook!");

      In order for the code to use all the functions used, we connect:
      using Windows.ApplicationModel.DataTransfer;
      using Windows.Storage;
      using Windows.Storage.Streams;

    6. We check our innovations. Open the application. We reproduce the process of creating the photo and click the “Share” button:

      Services are opened in which you can share the photo.


    Silverlight 8.1 is not only a continuation of the previous version of Silverlight 8.0, but also combines the new features that Windows Phone 8.1 and WinRT offer. And the transition to Silverlight 8.1 from applications of the previous version is not a long and time-consuming process.

    useful links

    New Windows Phone 8.1. What should an application developer do?
    Upgrading Windows Phone 8.0 application to Windows Phone 8.1 (XAML)
    Turning the Windows Store application into a universal
    Tutorial: Building Apps for windows Phone 8.1
    MSDN Library: Supported features for Windows Phone Silverlight 8.1 apps
    Microsoft Virtual Academy Training Courses (MVA)
    Download free or trial Visual Studio 2013
    Become a Windows Phone application developer
    Download the Silverlight 8.1 sample application from this article
    Download code samples with the basic features of Windows Phone 8.1 (c #, c ++, javascript)

    Also popular now: