
This is the third article from the series on updating Windows Phone 8.0 applications to version 8.1. This time, we’ll talk about the most difficult scenario: updating Windows Phone 8.0 (Silverlight) to Windows Phone 8.1 (XAML). This process is not as transparent and clear as
in the case of Silverlight or the Windows Store, where there are special actions in Visual Studio (Reterget) to change assemblies and links to them. In our case, we will have to rebuild the application manually for the new version. This is what we will do.
According to the results, we will
not only update the application to the new 8.1 platform , switch to using
WinRT and
be able to use its capabilities , but also get the draft of a
universal application for Phone and Windows with common code.
The work plan is as follows:
- Creating a new Windows Phone 8.1 project
- Code transfer
- Interface transfer
- Creating a Windows Store Project
I have a simple application developed for Windows Phone 8.0, which we will update to Windows Phone 8.1.
The application consists of two projects: the Windows Phone application project and the Portable Class Library with all the necessary classes. From third-party libraries, this application uses only
MVVMLight .
')

Creating a new Windows Phone 8.1 project
In order for the application to work not only on Windows Phone 8.1, but also on previous versions of Windows Phone, you will have to continue to support the Windows Phone 8.0 project along with the new project.
The most optimal solution is
to create a Windows Phone 8.1 project next to this Solution and
reuse the code for both projects as much as possible.
The second option is to fix the links to the libraries automatically in the existing project using the
Retarget to Windows Phone 8.1 action. But then you get a Silverlight 8.1 application, not XAML, and lose backward compatibility.

We will not go this way and we will create next to one more application for Windows Phone 8.1.
In Visual Studio, click
Add -
New Project . As a project template, select the
Blank App .

Code transfer
We are very lucky that the project uses MVVM, the code is reliably separated from the interface and we have a
Portable Class Library where there are already helper classes and objects. If you do not have this, then you will take out the models, controllers, and logic in PCL. Get something close to the structure in the picture below.

We connect the finished PCL to the project for Windows Phone 8.1 and add the rest of the used libraries.

Now you need to carefully copy the files from the project Windows Phone 8.0 and eliminate everything that will break. This is not as fast as it seems, but rather routinely.
In copied files, it is better to change the namespace to avoid conflicts in Solution. This can be done quickly using the Find and Replace feature.

If your Windows Phone 8.0 application supported several languages, and you used resource files for localization, then it is important to know that in 8.1 you simply cannot leave them in the
Resources folder. It will be necessary to
create new resource files and transfer the data there.

Interface transfer
If you try to compile and run the application - we will fail. The entire interface in XAML files will be cursed. In my two-page application 44 errors.
Fortunately, they are all typical and
relate to namespaces, controls, or their properties . The new Windows Phone 8.1 uses WinRT and there may
not be controls and properties that you used in the Silverlight Toolkit .

For example:
- The opening tag for the page is not <phone: PhoneApplicationPage ...> , but simply <Page ...> .
- Instead of <phone: PhoneApplicationPage.Resources>, you must use <Page.Resources> .
- Many standard styles will not be found and you will need to recreate them with your hands.
- Some properties of controls have changed or no longer exist.
As a result of this process, I got two almost identical-looking applications. Left Windows Phone 8.0, right Windows Phone 8.1.

Creating a Windows Store Project
After the Windows Phone 8.1 application runs, you can go further and
expand it to the Windows Store application to
publish to the Windows store .
This process is not as laborious as the previous one. It is necessary to select
Add Windows 8.1 in the context menu of the project
.
Two new projects will be created: a project for the Windows Store application and a
Shared project for the common code between Windows 8.1 and Phone 8.1 applications.

In the
Shared project, you can transfer most of the code, a part of xaml can be turned into user controls and reused.

If you start a Windows application, it will also be very similar to the Phone application and you will have to work separately on a more convenient design.

Conclusion
We got three apps: Windows Phone 8.0, Windows Phone 8.1 and Windows Store 8.1.
All code and other reusable files were moved from Windows Phone 8.1 and Windows Store projects to the Shared project for shared code or Portable Class Library.
In the project for Windows Phone 8.0, part of the code was also moved to PCL, but the interface and all features requiring the old API remained in this project.
Download the finished example here:
Universal.zip
useful links
New Windows Phone 8.1. What should an application developer do?Updating Windows Phone Silverlight 8.0 application to Windows Phone Silverlight 8.1We turn the Windows Store application into a universalFree online technology coursesDownload free or trial Visual Studio 2013Become a Windows Phone Application DeveloperCode samples with the main features of Windows Phone 8.1 (c #, c ++, javascript)