8

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.

parsley72
  • 8,449
  • 8
  • 65
  • 98

1 Answers1

9

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
Gerald Versluis
  • 30,492
  • 6
  • 73
  • 100
  • In your note , you said that we should add "all the NuGet Packages",which packages ?? in many sites i see that they demand only to add Xamarin.forms Nuget package. – A.HADDAD Apr 15 '19 at 18:15
  • 1
    Added a bit of clarification on that, you were right. I meant NuGet packages like plugins etc. that you might have installed on other projects already. If you're setting up a clean project, the Xamarin.Forms package is enough. – Gerald Versluis Apr 15 '19 at 18:24
  • ok i already have 15 other projects in my solution. that means that i need to add all the nuget packages installed in my solution ? or only those of .shared(.NetStandard Library) project that UWP reference ? – A.HADDAD Apr 15 '19 at 18:45
  • Not necessarily, only the ones that you normally install on your shared project and your iOS and Android project, is the one you now need to add to UWP as well. If your NuGet is just installed in the shared library, you probably don't need to install it on UWP. – Gerald Versluis Apr 16 '19 at 06:08
  • Ok in my .ios & .android projects i have nuget packages, that are only supported for ios and android. ex: [Acr.Support](https://www.nuget.org/packages/Acr.Support/) Does that means that i can't extend my project to use uwp ? – A.HADDAD Apr 16 '19 at 13:28
  • It seems that Acr.Support is targeting iOS and Android specifically. The NuGet packages I mean are more the ones that you have to install in your _shared_ library as well as your platform libraries. For example; Acr.UserDialogs – Gerald Versluis Apr 16 '19 at 13:34
  • I added all the nuget packages of *.shared projects to *.uwp project , the result: the uwp project dosen't launch – A.HADDAD Apr 16 '19 at 14:05
  • [In github](https://github.com/MicrosoftDocs/xamarin-docs/issues/1616) , they told me that because there is a nuget package that dosen't support uwp , the project can't be extended with uwp. so not only the packages available on shared projects should be the same as you said ? – A.HADDAD Apr 17 '19 at 17:05
  • I have extended my aspnetBoilerplate(aspnetzero) project with uwp , the only nedded packages were xamarin.forms and Win2D.uwp – A.HADDAD May 02 '19 at 09:28
  • 1
    @Gerald Versluis here you explained perfectly too: https://www.youtube.com/watch?v=mbIvG8ripcw&t=590s – Junior Grão Jul 11 '21 at 14:26