LittleFunny
LittleFunny

Reputation: 8405

Xamarin Form: How to apply NamedSize.Medium to OnIdiom element

I can change the font size by passing values to OnIdiom Element for different device. But how do I pass FontSize Medium to the OnIdiom in xaml, what is the TypeArguments to passed into.

<Style x:Name="normalFont">
    <Setter Property="FontSize">
        <Setter.Value>
        <OnIdiom.Phone>
        <OnPlatform x:TypeArguments="x:Double" iOS="Small" Android="Small" />
            </OnIdiom.Phone>
            <OnIdiom.Tablet>
                <OnPlatform x:TypeArguments="x:Double" iOS="Medium" Android="Medium" />
            </OnIdiom.Tablet>
        </Setter.Value>
    </Setter>
</Style>

I know it won't be double what type should I put.

Upvotes: 1

Views: 1759

Answers (4)

LAlvarenga
LAlvarenga

Reputation: 11

This could be a work around:

<Style x:Key="normalFont" TargetType="Label">
  <Setter Property="FontSize" Value="{OnIdiom Phone=Small, Tablet=Medium}" />
</Style>

Upvotes: 0

David Sancho
David Sancho

Reputation: 1

Here you can see how you must do it.

https://forums.xamarin.com/discussion/122883/error-setvalue-can-not-convert-large-to-type-system-double-when-using-style-with-onidiom

Basically, you must create a MarkupExtension to handle the conversion.

Upvotes: 0

ahmed roshdy
ahmed roshdy

Reputation: 71

I did it in Xaml.cs file attached with xaml in Constructor add this

if (Device.Idiom == TargetIdiom.Phone)
    {
      normalFont.FontSize=Device.GetNamedSize(NamedSize.Small,typeof(Style));
        }
        else if (Device.Idiom == TargetIdiom.Tablet)
        {
            normalFont.FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Style));
        }

Upvotes: 1

Pratik
Pratik

Reputation: 720

put

x:TypeArguments="NamedSize"

instead of

x:TypeArguments="x:Double"

Upvotes: 0

Related Questions