Reputation: 7709
In a style in xamarin forms (defined in xaml) I can define values platform specific, like this:
<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>
Can I also define the style in a way, so that the value of "Font" is kept to the default (not set at all) for some plarforms?
Something like this:
<Style x:Key="MyTitleLabel" TargetType="Label"">
<OnPlatform>
<OnPlatform.Android>
<Setter Property="Font" Value="30" />
</OnPlatform.Androud>
</OnPlatform>
</Style>
Upvotes: 3
Views: 2017
Reputation: 13601
There is no way avoid setting a value - if no value is specified it will default to default(T)
.
But, with the latest XF version (> 2.4.0.282) there is a Default
property available that you can use to specify the fallback value.
<!-- specify default value here -->
<OnPlatform x:TypeArguments="x:Double" Default="25">
<OnPlatform.Android>
<Setter Property="Font" Value="30"/>
</OnPlatform.Android>
</OnPlatform>
Upvotes: 3
Reputation: 1421
This should work:
<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>
Upvotes: 2