Nestor
Nestor

Reputation: 8384

How to apply Idiom filtering to a Style in Xamarin.Forms

I intend to support tablets with my Xamarin.Forms app, so I checked how to create different layouts.

According to this blog entry, I can use the OnIdiom switch in the XAML code like this:

<Grid.RowSpacing>
    <OnIdiom x:TypeArguments="x:Double"
             Phone="10"
             Tablet="20"/>
</Grid.RowSpacing>

However, I also intend to create styles to minimize the code to write. Unfortunately I can't specify a Style Value with a switch on Idiom, like this:

<Style x:Key="BoldField" TargetType="Label">
    <Setter Property="FontAttributes" Value="<OnIdiom x:TypeArguments="FontAttribute" Phone="Bold" Tablet="Normal"/>" />
</Style>

Can I create a style that switches on the idiom?

Upvotes: 0

Views: 1800

Answers (1)

Yehor Hromadskyi
Yehor Hromadskyi

Reputation: 3398

I think, you could. Try something like this:

<Style x:Key="BoldField" TargetType="Label">
  <Setter Property="FontAttributes">
    <Setter.Value>
      <OnIdiom x:TypeArguments="FontAttribute" Phone="Bold" Tablet="Normal"/>
    </Setter.Value>
  </Setter>
</Style>

Upvotes: 6

Related Questions