如何将UWP目标添加到现有的Xamarin Forms项目中?

问题描述 投票:2回答:1

我有一个现有的Xamarin Forms应用程序,可以为Android和iOS构建。我想添加一个UWP目标,以便我可以看到该应用程序在Windows上的表现。我假设我可以这样做,而无需为Windows创建新的UI?

我在Windows 10上使用Visual Studio 2015。

visual-studio-2015 xamarin.forms xamarin.uwp
1个回答
3
投票

你应该能够遵循这个Xamarin documentation page

旧xamarin.com链接old documentation page

它包含几个步骤,一切都在Visual Studio中,因为Xamarin Studio不支持UWP:

  1. 在您的解决方案中添加一个干净的UWP项目。
  2. 将Xamarin.Forms NuGet包添加到您的UWP项目中,确保该版本与您的其他项目同步
  3. 在Build> Configuration Manager下,确保正在构建和部署您的UWP项目

Building and deploying your UWP app

  1. 右键单击项目>添加>引用并引用您的PCL或共享项目

Referencing your shared project

  1. OnLaunched方法中编辑App.xaml.cs(模板中的第63行):
    // under this line
    rootFrame.NavigationFailed += OnNavigationFailed;
    // add this line
    Xamarin.Forms.Forms.Init (e); // requires the `e` parameter
  1. 在MainPage.xaml中删除Page标签中的所有内容,它应该是一个空的Grid标签。
  2. 同样在MainPage.xaml中添加此命名空间:xmlns:forms="using:Xamarin.Forms.Platform.UWP"
  3. 仍然在MainPage.xaml中将Page标记更改为forms:WindowsPage
  4. 在MainPage.xaml.cs中删除Page的继承,使它成为public sealed partial class MainPage // REMOVE ": Page"
  5. 仍然在MainPage.xaml.cs中在构造函数中添加LoadApplication,如下所示:
    // below this existing line
    this.InitializeComponent();
    // add this line
    LoadApplication(new YOUR_NAMESPACE.App());

另请注意,您必须提供图像等资源,并添加您可能已安装在其他项目中的所有使用过的NuGet软件包,例如您正在使用的插件。在后一种情况下,最好检查是否所有包都可用于UWP。

还有一些已知问题:

  • 某些视图/页面的外观尚未最终确定导航周围有几个已知的crashers文本对齐在某些标题中可能不完美
© www.soinside.com 2019 - 2024. All rights reserved.