【问题标题】:Xamarin Forms from Windows Phone 8.1(RT) - xaml exceptionsWindows Phone 8.1(RT) 中的 Xamarin 表单 - xaml 异常
【发布时间】:2017-04-13 18:32:47
【问题描述】:

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

-windows phone 8.1 设备

-windows phone 8.1 模拟器

-手机模拟器10.0.14393(x86)

它工作正常。 但是当我在 Windows 10 设备(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 代码吗?
  • 我在我的问题中添加了一个小例子
  • ColumnDefinitions 是 Grid 的一部分(基本上是 Grid.ColumnDefinitions) - 您需要为整个页面提供 XAML,以便我们查看它有什么问题 - 而不仅仅是一个小 sn- p.
  • 这不是我的 xaml 的问题。这是我的项目和 Xamarin Forms(2.3.4.231) 的问题。我的代码在模拟器(8.1 和 10)中工作,但在 Windows 10 设备(arm)中不工作。当我降级到 XF 2.3.2.127 时,我的代码在 Windows 10 设备中工作。
  • 可能是您忘记在 app.xaml.cs 中调用 InitializeComponent(); 了吗?

标签: xaml windows-phone-8.1 xamarin.forms win-universal-app


【解决方案1】:

我解决了这个问题。错误出现在我的 xaml 代码中。 Xamarin Forms 2.3 在 xaml 中不支持 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 代码中使用了这个类。但是在 XF 2.3.4 Device.OS 中已经过时了。我从我的 xaml 代码中删除了 XOnPlatform。我在我的 xaml 代码中使用 OnPlatform。这是工作。宾果游戏:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-23
    • 2016-08-22
    • 2014-11-04
    • 1970-01-01
    • 1970-01-01
    • 2016-06-10
    相关资源
    最近更新 更多