Monday, 21 May 2018

How to convert WPF project to UWP App

With the help of Desktop App Converter, Now you can easily convert your WPF App to UWP within few clicks. I will walk you through the steps on how to convert your traditional WPF App to UWP App.

Before that I would like to mention below few reasons about why you should migrate to UWP Apps and what benefits you can get by doing so:


✔️ Streamlined deployment. Apps and games that use the bridge have a great deployment experience. This experience ensures that users can confidently install an app and update it. If a user chooses to uninstall the app, it's removed completely with no trace left behind. This reduces time authoring setup experiences and keeping users up-to-date.
✔️ Automatic updates and licensing. Your app can participate in the Microsoft Store's built-in licensing and automatic update facilities. Automatic update is a highly reliable and efficient mechanism, because only the changed parts of files are downloaded.
✔️ Increased reach and simplified monetization. Choosing to distribute through the Microsoft Store expands your reach to millions of Windows 10 users, who can acquire apps, games and in-app purchases with local payment options.
✔️ Add UWP features. At your own pace, you can add UWP features to your app's package, like a XAML user-interface, live tile updates, UWP background tasks, app services, and many more.
✔️ Broadened use-cases across device. Using the bridge, you can gradually migrate your code to the Universal Windows Platform to reach every Windows 10 device, including phones, Xbox One and HoloLens.
You can refer to MSDN if you are interested to learn more.
Prerequisite before starting the process:
  • Windows 10 OS
  • Visual Studio 2017
  • Windows 10 SDK
Let's start converting WPF App to UWP App:

1. Below is my simple WPF project structure which just print Hello World.



2. Now right click on the solution and select Add -> New Project, A project template dialog will appear select 'Windows Appliaction Packaging Project'  under 'Windows Universal'.


3. After selecting the project another modal dialog will appear which will ask you to select SDK minimum and maximum target version. For more info please refer this MSDN link.I am selecting Anniversary Update(Build 14393) as Minimum version and Fall Creators Update(Build 16299) as target version.



4. New project is now added in your solution.



5. Right click on the UWP project -> Add Reference -> Give reference to your WPF App.



6. Now build your solution and you are ready to go. You can create a store package and can directly publish your app in the store.Now you might be wondering how to add UWP functionalities to your App. Keep following the article, Below I will show on how you can consume UWP API's in your WPF Application.


7. Right click on References of your WPF Applicatoin. Select “Add Reference…” from the context menu. On the left of the Reference Manager, choose Browse and find the following file: C:\Program Files (x86)\Windows Kits\10\UnionMetadata\winmd. Add it to your project as a reference. Note: You will need to change the filter to “All Files”.



8. Right click on References of your WPF Application. Select “Add Reference…” from the context menu. On the left of the Reference Manager, go to Browse and find the directory “C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5”. Add System.Runtime.WindowsRuntime.dll to your project.



9. Now you can access UWP API's from your WPF project, in below example I am accessing ApplicationData API to create File.


var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(fileName, CreationCollisionOption.OpenIfExists);

10. To test your application you need to set UWP App as a Startup project. To do that right click on UWP App and select 'Set as Startup Project'. 


I hope you get to know on how you can convert your WPF Application to UWP App and take advantage of latest and greatest API and reaching more user base by submitting your App to Microsoft Store.
Feel free to comment below if you have any questions or suggestions.
Happy Coding! :)