如何将UWP目标添加到现有的Xamarin Forms项目?
我有一个现有的Xamarin Forms应用程序,可以为Android和iOS构建。我想添加一个UWP目标,这样我就可以看到应用程序在Windows上的表现。我假设我可以做到这一点,而无需为Windows创建新的用户界面?如何将UWP目标添加到现有的Xamarin Forms项目?
我使用Visual Studio 2015年在Windows 10
你应该能够跟随这Xamarin documentation page
它包括几个步骤的,一切都在Visual Studio中作为不支持UWP在Xamarin Studio中:
- 在您的解决方案中添加一个干净的UWP项目。
- 的Xamarin.Forms NuGet包添加到您的UWP项目,确保版本同步与其他项目
- 在构建>配置管理器确保您UWP项目正在构建和部署
- 右击项目>添加>参考和引用您PCL或共享项目
- 修改您App.xaml.cs在
OnLaunched
方法(围绕在模板线63)的更多信息: In MainPage.xaml删除中的所有内容标签,它应该是一个空的
Grid
标签。另外在MainPage.xaml中添加这个命名空间:
xmlns:forms="using:Xamarin.Forms.Platform.UWP"
仍然在MainPage.xaml中改变
Page
标签forms:WindowsPage
在MainPage.xaml.cs中删除
Page
的继承,所以它变成public sealed partial class MainPage // REMOVE ": Page"
仍然在MainPage.xaml.cs中在构造函数中添加
LoadApplication
这样的:
// under this line rootFrame.NavigationFailed += OnNavigationFailed; // add this line Xamarin.Forms.Forms.Init (e); // requires the `e` parameter
// below this existing line this.InitializeComponent(); // add this line LoadApplication(new YOUR_NAMESPACE.App());
还要注意你必须提供的资源,如图像,并添加所有使用的NuGet包。在后一种情况下,最好检查是否所有软件包都可用于UWP。
有几个已知问题,以及:
- 一些看法/网页的外观,还没有最后定下来大约有导航文本对齐一对夫妇 知不速之客可能不是完美的 一些标题
https://developer.xamarin.com/guides/xamarin-forms/platform-features/windows/installation/universal/ – magicandre1981