Xamarin Forms 来自 Windows Phone 8.1(RT) - xaml 异常

Xamarin Forms from Windows Phone 8.1(RT) - xaml exceptions

我使用 Xamarin Forms 为 Windows Phone 8.1(RT) 创建了应用程序。我将 XF 更新到最新版本 2.3.4.231。我的应用在 运行:

-windows phone 8.1 设备

-windows phone 8.1 模拟器

-手机模拟器10.0.14393(x86)

它工作正常。 但是当我 运行 app 到 Windows 10 device(arm) 时,我有很多例外。我尝试了不同的起始页并获得了鬃毛异常(来自 xaml):

-Cannot assign property \"ColumnDefinitions\": Property does not exists, or is not assignable, or mismatching type between value and property"

-StaticResource not found for key ...

-An item with the same key has already been added

所有这些错误都与 xaml 有关。 我不使用 XamlCompilationOptions.Compile。

我的应用程序的最后一个工作版本 XF 2.3.2.127

这个小例子: 我改变了起始页。我有例外:

-StaticResource not found for key StandardPadding

这是我页面的一部分:

 <StackLayout  Padding="{StaticResource StandardPadding}">

我在 App.xaml 中的资源:

 <Application.Resources>
    <ResourceDictionary>
      <Thickness x:Key="StandardPadding">16</Thickness>
    </ResourceDictionary>
</Application.Resources>

我解决了这个问题。错误出在我的 xaml 代码中。 xaml 中不支持 Xamarin Forms 2.3 Windows OnPlatform。所以我使用了这个扩展:

public class XOnPlatform<T> : OnPlatform<T>
{
    public T Windows { get; set; }

    public static implicit operator T(XOnPlatform<T> onPlatform)
    {
        if (Device.OS == TargetPlatform.Windows)
        {
            return onPlatform.Windows;
        }

        return (OnPlatform<T>)onPlatform;
    }
}

我在 xaml 代码中使用了这个 class。但在 XF 2.3.4 中 Device.OS 已过时。我从 xaml 代码中删除了 XOnPlatform。我在 xaml code.This 中使用 OnPlatform 是工作。宾果:)