Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin 如何在样式资源中包含OnPlatform?_Xamarin_Xamarin.forms - Fatal编程技术网

Xamarin 如何在样式资源中包含OnPlatform?

Xamarin 如何在样式资源中包含OnPlatform?,xamarin,xamarin.forms,Xamarin,Xamarin.forms,我有这种风格: <Style x:Key="pointButton" TargetType="Button"> <Setter Property="BorderColor" Value="#999999"/> <Setter Property="BorderWidth" Value="1" /> <Setter Property="TextColor" Value="#

我有这种风格:

       <Style x:Key="pointButton" TargetType="Button">
            <Setter Property="BorderColor" Value="#999999"/>
            <Setter Property="BorderWidth" Value="1" />
            <Setter Property="TextColor" Value="#AAAAAA" />
            <Setter Property="FontAttributes" Value="Bold" />
            <Setter Property="HorizontalOptions" Value="FillAndExpand" />
            <Setter Property="VerticalOptions" Value="StartAndExpand" />
            <Setter Property="Margin" Value="10,10,10,10" />
            <Setter Property="HeightRequest" Value="40" />
        </Style>

我想包括这个。可能吗

<Button.FontSize>
   <OnPlatform x:TypeArguments="x:Double" iOS="25" Android="20" />
</Button.FontSize>

将每个属性定义为OnPlatform

<OnPlatform x:Key="MyFontSize" x:TypeArguments="x:Double" iOS="14" Android="14" WinPhone="14" />

并引用yout按钮样式,如

<Style x:Key="MyButtonStyle" TargetType="{x:Type Button}">
    <Setter Property="FontSize" Value="{StaticResource MyFontSize}" />
</Style>

使用新的XamarinOnPlatform可以直接在样式标签中定义平台样式:

<Style x:Key="buttonStyle" TargetType="Button">
  <Setter Property="FontSize">
    <OnPlatform x:TypeArguments="x:Double">
      <On Platform="Android">40</On>
        <On Platform="iOS">10</On>
     </OnPlatform>
   </Setter>
</Style>

40
10