【问题标题】:How to apply Idiom filtering to a Style in Xamarin.Forms如何将 Idiom 过滤应用于 Xamarin.Forms 中的样式
【发布时间】:2016-09-01 16:06:06
【问题描述】:

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

根据this blog entry,我可以像这样在XAML代码中使用OnIdiom开关:

<Grid.RowSpacing>
    <OnIdiom x:TypeArguments="x:Double"
             Phone="10"
             Tablet="20"/>
</Grid.RowSpacing>

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

<Style x:Key="BoldField" TargetType="Label">
    <Setter Property="FontAttributes" Value="<OnIdiom x:TypeArguments="FontAttribute" Phone="Bold" Tablet="Normal"/>" />
</Style>

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

【问题讨论】:

    标签: xamarin.forms xamarin.forms-styles


    【解决方案1】:

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

    <Style x:Key="BoldField" TargetType="Label">
      <Setter Property="FontAttributes">
        <Setter.Value>
          <OnIdiom x:TypeArguments="FontAttribute" Phone="Bold" Tablet="Normal"/>
        </Setter.Value>
      </Setter>
    </Style>
    

    【讨论】:

    • 很明显,但我想不通 :) 谢谢,它有效
    猜你喜欢
    • 2019-03-26
    • 1970-01-01
    • 2016-12-31
    • 1970-01-01
    • 2016-12-16
    • 2023-01-28
    • 2018-05-19
    • 2012-01-31
    • 1970-01-01
    相关资源
    最近更新 更多