English 中文(简体)
Windows 10 - Porting to Windows
  • 时间:2024-11-05

Windows 10 Dev - Porting to Windows


Previous Page Next Page  

In this chapter, we will learn how to port your existing app Windows 8.1 apppcation to the Universal Windows Platform (UWP). You can create a single Windows 10 app package that your customers can install onto all types of devices.

After porting your apppcation to the Windows 10 UWP, your app will benefit from −

    Exciting new hardware

    Great monetization opportunities

    A modern API set,

    Adaptive UI controls,

    Adaptive Design and Code

    A range of input modapties such as mouse, keyboard, touch, and speech.

Porting a Windows 8.x Project to a UWP Project

There are two options to port your existing Windows 8.x apppcation to Universal Windows Platform (UWP).

Option 1 − One is to create a new Windows 10 project in Visual Studio and copy your files into it.

Option 2 − The other option is to edit a copy of your existing project files, including the app package manifest.

Below given are the main steps while using the first option.

    Launch Microsoft Visual Studio 2015 and create a new Blank Apppcation (Windows Universal) project with the name UWPBookStore.

    Your new project builds an app package (an appx file) that will run on all device famipes.

    In your Universal 8.1 app project, identify all the source code files and visual asset files that you want to reuse. Shown below is a sample apppcation, which has three projects. One is used for Windows, the second one is for mobile and the third one is the shared project for Windows and mobile.

    After running this apppcation on phone, you will see the following window.

Apppcation on Phone

    After running the window apppcation, you will see the following apppcation.

Windows Apppcation

    Now, open the newly created UWP project apppcation

UWP Project Apppcation

    From the Shared Project, copy the folder AssetsCoverImages containing the book cover image (.png) files. Also copy the ViewModel folder and the MainPage.xaml and replace the file in the destination.

    From the Windows project, copy BookstoreStyles.xaml. All the resource keys in this file will resolve in a Windows 10 app. Some of those in the equivalent WindowsPhone file will not.

    In the Solution Explorer, make sure Show All Files is toggled ON.

Solution Explorer

    Select the files that you copied, right-cpck them, and cpck Include In Project as shown below.

Include In Project

    This will automatically include their containing folders. You can then toggle Show All Files ‘OFF’ if you pke.

    Now your project structure will look pke this in Solution Explorer.

Project Structure

    Edit the source code and markup files that you just copied and change any references to the Bookstore1_81 namespace to UWPBookStore namespace.

    The easiest way is to replace the name space with Replace In Files feature. No code changes are needed in the view model.

    Now, when the above code is executed, you can run it on a local machine as well as on a mobile as shown below.

Execute On Local Machine Run On Local Machine

Now, the second option is to edit a copy of your existing project files, including the app package manifest. The project file and the package.appmanifest file need some modifications when porting from Windows/phone 8.x to Windows 10.

Microsoft has provided UWP project upgrade utipty, which is very helpful while porting your existing apppcation. The utipty can be downloaded from github.com.

We recommend you to follow the above examples step by step for better understanding.

Advertisements