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

后端 未结 1 1013
野的像风
野的像风 2021-01-05 18:48

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 t

相关标签:
1条回答
  • 2021-01-05 18:57

    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

    1. right-click on project > Add > Reference and reference your PCL or 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
    0 讨论(0)
提交回复
热议问题