问题
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.
回答1:
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:
- Add a clean UWP project to your solution.
- Add the Xamarin.Forms NuGet package to your UWP project, make sure the version is in sync with your other projects
- Under Build > Configuration Manager make sure your UWP project is being built and deployed
- right-click on project > Add > Reference and reference your PCL or Shared project
- 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
In MainPage.xaml remove all content in the
Page
tags, it should be an emptyGrid
tag.Also in the MainPage.xaml add this namespace:
xmlns:forms="using:Xamarin.Forms.Platform.UWP"
Still in the MainPage.xaml change the
Page
tag toforms:WindowsPage
In the MainPage.xaml.cs remove the inheritance of
Page
so it becomespublic sealed partial class MainPage // REMOVE ": Page"
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
来源:https://stackoverflow.com/questions/41192203/how-can-i-add-a-uwp-target-to-an-existing-xamarin-forms-project