Nul*_*nce 2 xaml static-binding xamarin xamarin.forms
以前我能做到这样的事情
<OnPlatform x:TypeArguments="Color" Android="{StaticResource Primary}"/>
Run Code Online (Sandbox Code Playgroud)
现在,该语法已被弃用,我正在尝试这样做:
<OnPlatform x:TypeArguments="Color">
<On Platform="Android">{StaticResource Primary}</On>
</OnPlatform>
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
Cannot convert "{StaticResource Primary}" into Xamarin.Forms.Color
Run Code Online (Sandbox Code Playgroud)
我的语法应该如何?
因为StaticResource是标记扩展,您可以通过属性用法或元素用法来使用它
例如,试试这个:
<OnPlatform x:TypeArguments="Color">
<On Platform="Android" Value="{StaticResource Primary}" />
</OnPlatform>
Run Code Online (Sandbox Code Playgroud)
要么,
<OnPlatform x:TypeArguments="Color">
<On Platform="Android">
<StaticResource Key="Primary" />
</On>
</OnPlatform>
Run Code Online (Sandbox Code Playgroud)