2017-10-20 63 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> 
相關問題