2

以前我能够做这样的事情

<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

我的语法应该如何?

4

1 回答 1

8

因为StaticResource是标记扩展,您可以通过属性使用或元素使用来使用它

例如,试试这个:

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

或者,

<OnPlatform x:TypeArguments="Color">
    <On Platform="Android">
         <StaticResource Key="Primary" />
    </On>
</OnPlatform>
于 2017-05-10T17:27:51.100 回答