【问题标题】:Xamarin's new way of performing OnPlatform StaticResource bindingXamarin 执行 OnPlatform StaticResource 绑定的新方法
【发布时间】:2017-05-10 17:13:51
【问题描述】:

以前我可以做这样的事情

<OnPlatform x:TypeArguments="Color" Android="{StaticResource Primary}"/>

现在,该语法已被弃用,我正在尝试这样做:

<OnPlatform x:TypeArguments="Color">
   <On Platform="Android">{StaticResource Primary}</On>
</OnPlatform>

但我收到以下错误:

Cannot convert "{StaticResource Primary}" into Xamarin.Forms.Color

我的语法应该如何?

【问题讨论】:

    标签: xaml xamarin xamarin.forms static-binding


    【解决方案1】:

    因为StaticResource是一个标记扩展,你可以通过attribute usage, or element usage来使用它

    例如,试试这个:

    <OnPlatform x:TypeArguments="Color">
        <On Platform="Android" Value="{StaticResource Primary}" />
    </OnPlatform>
    

    或者,

    <OnPlatform x:TypeArguments="Color">
        <On Platform="Android">
             <StaticResource Key="Primary" />
        </On>
    </OnPlatform>
    

    【讨论】:

      猜你喜欢
      • 2017-02-09
      • 2021-08-10
      • 2017-06-05
      • 1970-01-01
      • 2013-07-21
      • 2014-10-21
      • 2017-12-14
      • 1970-01-01
      • 2015-04-14
      相关资源
      最近更新 更多