Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a UWP target to an existing Xamarin Forms project?

I have an existing Xamarin Forms app that's setup to build for Android and iOS. I want to add a UWP target so I can see how the app performs on Windows. I assume I can do this without having to create a new UI for Windows?

I'm using Visual Studio 2015 on Windows 10.

like image 473
parsley72 Avatar asked Dec 16 '16 20:12

parsley72


1 Answers

You should be able to following this Xamarin documentation page

Old xamarin.com link old documentation page

It consists of a couple of steps, everything is in Visual Studio as UWP is not supported in Xamarin Studio:

  1. Add a clean UWP project to your solution.
  2. Add the Xamarin.Forms NuGet package to your UWP project, make sure the version is in sync with your other projects
  3. Under Build > Configuration Manager make sure your UWP project is being built and deployed

Building and deploying your UWP app

  1. right-click on project > Add > Reference and reference your PCL or Shared project

Referencing your shared project

  1. Edit your App.xaml.cs in the OnLaunched method (around line 63 in the template) do:
    // under this line
    rootFrame.NavigationFailed += OnNavigationFailed;
    // add this line
    Xamarin.Forms.Forms.Init (e); // requires the `e` parameter
  1. In MainPage.xaml remove all content in the Page tags, it should be an empty Grid tag.

  2. Also in the MainPage.xaml add this namespace: xmlns:forms="using:Xamarin.Forms.Platform.UWP"

  3. Still in the MainPage.xaml change the Page tag to forms:WindowsPage

  4. In the MainPage.xaml.cs remove the inheritance of Page so it becomes public sealed partial class MainPage // REMOVE ": Page"

  5. Still in the MainPage.xaml.cs add the LoadApplication in the constructor like this:

    // below this existing line
    this.InitializeComponent();
    // add this line
    LoadApplication(new YOUR_NAMESPACE.App());

Also note you do have to provide the resources like images and add all used NuGet packages that you might have installed in other projects like plugins you're using. In the latter case, it is probably best to check if all packages are available for UWP.

There are a couple of known issues as well:

  • The look of some views/pages is not yet finalized There are a couple known crashers around navigation Text alignment may not be perfect in some titles
like image 73
Gerald Versluis Avatar answered Oct 16 '22 10:10

Gerald Versluis