Xamarin表单:如何将NamedSize.Medium应用于OnIdiom元素

问题描述 投票:0回答:2

我可以通过将值传递给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
2个回答
0
投票

X:TypeArguments = “NamedSize”

代替

X:TypeArguments = “X:双击”


0
投票

我在Xaml.cs文件中使用附加的xaml在Constructor中添加了这个

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));
        }
© www.soinside.com 2019 - 2024. All rights reserved.