【问题标题】:Xamarin Form: How to apply NamedSize.Medium to OnIdiom elementXamarin 表单:如何将 NamedSize.Medium 应用于 OnIdiom 元素
【发布时间】:2017-11-03 07:56:36
【问题描述】:

我可以通过将值传递给不同设备的 OnIdiom 元素来更改字体大小。但是如何将 FontSize Medium 传递给 xaml 中的 OnIdiom,要传入的 TypeArguments 是什么。

<Style x:Name="normalFont">
    <Setter Property="FontSize">
        <Setter.Value>
        <OnIdiom.Phone>
        <OnPlatform x:TypeArguments="x:Double" iOS="Small" Android="Small" />
            </OnIdiom.Phone>
            <OnIdiom.Tablet>
                <OnPlatform x:TypeArguments="x:Double" iOS="Medium" Android="Medium" />
            </OnIdiom.Tablet>
        </Setter.Value>
    </Setter>
</Style>

我知道我应该放什么类型不会加倍。

【问题讨论】:

    标签: xaml xamarin styles font-size


    【解决方案1】:

    在这里你可以看到你必须如何去做。

    https://forums.xamarin.com/discussion/122883/error-setvalue-can-not-convert-large-to-type-system-double-when-using-style-with-onidiom

    基本上,您必须创建一个 MarkupExtension 来处理转换。

    【讨论】:

    • 虽然这在理论上可以回答这个问题,it would be preferable 在此处包含答案的基本部分,并提供链接以供参考。
    【解决方案2】:

    我是在 Xaml 附带的 Xaml.cs 文件中完成的 在构造函数中添加这个

    if (Device.Idiom == TargetIdiom.Phone)
        {
          normalFont.FontSize=Device.GetNamedSize(NamedSize.Small,typeof(Style));
            }
            else if (Device.Idiom == TargetIdiom.Tablet)
            {
                normalFont.FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Style));
            }
    

    【讨论】:

      【解决方案3】:

      x:TypeArguments="NamedSize"

      而不是

      x:TypeArguments="x:Double"

      【讨论】:

      • 使用 x:TypeArguments="NamedSize" 代替 x:TypeArguments="x:Double"
      • 错误 XLS0504 属性“FontSize”不支持“OnIdiom (NamedSize)”类型的值
      猜你喜欢
      • 1970-01-01
      • 2021-08-10
      • 2012-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-03
      • 1970-01-01
      • 2020-01-05
      相关资源
      最近更新 更多