2017-10-20 58 views
3

设置样式值在xamarin形式风格(在XAML中定义),我可以定义值特定平台的,就像这样:Xamarin.Forms:如何只在特定平台

<OnPlatform x:TypeArguments="Font" Android="30" iOS="40" WinPhone="20" x:Key="TitleFontSize" /> 

<Style x:Key="MyTitleLabel" TargetType="Label""> 
    <Setter Property="Font" Value="{StaticResource TitleFontSize}" /> 
</Style> 

可我还定义了风格的方式,使“字体”的价值保持默认(根本没有设置)的一些plarforms?

事情是这样的:

<Style x:Key="MyTitleLabel" TargetType="Label""> 
    <OnPlatform> 
    <OnPlatform.Android> 
     <Setter Property="Font" Value="30" /> 
    </OnPlatform.Androud> 
    </OnPlatform> 
</Style> 

回答

1

有没有办法避免设置的值 - 如果没有指定值,则默认为default(T)

但是,使用最新的XF版本(> 2.4.0.282),有一个Default property可用,您可以使用它来指定故障预置值。

<OnPlatform x:TypeArguments="x:Double" Default="25"> <!-- specify default value here --> 
    <OnPlatform.Android> 
     <Setter Property="Font" Value="30" /> 
    </OnPlatform.Androud> 
</OnPlatform> 
1

这应该工作:

<Style x:Key="MyTitleLabel" TargetType="Label""> 
    <Setter Property="Font"> 
    <Setter.Value>     
     <OnPlatform x:TypeArguments="x:Double"> 
      <On Platform="Android">30</On> 
      <!--?<On Platform="iOS">20</On>--> 
     </OnPlatform> 
    </Setter.Value> 
    </Setter> 
</Style> 
相关问题