如何将习语过滤应用于 Xamarin.Forms 中的样式

Nes*_*tor 0 xamarin.forms xamarin.forms-styles

我打算用我的 Xamarin.Forms 应用程序支持平板电脑,所以我检查了如何创建不同的布局。

根据此博客条目,我可以OnIdiom在 XAML 代码中使用开关,如下所示:

<Grid.RowSpacing>
    <OnIdiom x:TypeArguments="x:Double"
             Phone="10"
             Tablet="20"/>
</Grid.RowSpacing>
Run Code Online (Sandbox Code Playgroud)

但是,我也打算创建样式以最小化要编写的代码。不幸的是,我无法通过 Idiom 上的开关指定样式值,如下所示:

<Style x:Key="BoldField" TargetType="Label">
    <Setter Property="FontAttributes" Value="<OnIdiom x:TypeArguments="FontAttribute" Phone="Bold" Tablet="Normal"/>" />
</Style>
Run Code Online (Sandbox Code Playgroud)

我可以创建一个可以切换成语的样式吗?

Yeh*_*kyi 5

我想,你可以。尝试这样的事情:

<Style x:Key="BoldField" TargetType="Label">
  <Setter Property="FontAttributes">
    <Setter.Value>
      <OnIdiom x:TypeArguments="FontAttribute" Phone="Bold" Tablet="Normal"/>
    </Setter.Value>
  </Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)