我有这种风格:
<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>
答案 0 :(得分:5)
将每个属性定义为OnPlatform
<OnPlatform x:Key="MyFontSize" x:TypeArguments="x:Double" iOS="14" Android="14" WinPhone="14" />
并按照
等按钮样式引用它<Style x:Key="MyButtonStyle" TargetType="{x:Type Button}">
<Setter Property="FontSize" Value="{StaticResource MyFontSize}" />
</Style>
答案 1 :(得分:1)
使用新的Xamarin OnPlatform specification可以直接在 style 标签中定义平台样式:
<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>