Define Global Style with platform specific values

MigokMigok Member ✭✭

Hi,

Is it possible to define a global style with values depending on platform ?

For example in my App.xaml i have a button :

<Style x:Key="ConfigBtnStyle" TargetType="Button">
                <Setter Property="BackgroundColor" Value="#e6e6e6" />
                <Setter Property="BorderWidth" Value="0"/>
                <Setter Property="TextColor" Value="#6c6869"/>
            </Style>

How can I set a padding for iOS only ?

Actually I override the style on each .xaml file to force padding on iOS like this

<Button.Padding>
                            <OnPlatform x:TypeArguments="Thickness">
                                <On Platform="iOS">20,0,20,0</On>
                                <On Platform="Default">0</On>
                            </OnPlatform>
                        </Button.Padding>

Thanks

Best Answer

Answers

  • MigokMigok Member ✭✭

    Ok great, i didnt expected this to work ^^

    <Style x:Key="ConfigBtnStyle" TargetType="Button">
                    <Setter Property="BackgroundColor" Value="#e6e6e6" />
                    <Setter Property="BorderWidth" Value="0"/>
                    <Setter Property="TextColor" Value="#6c6869"/>
                    <Setter Property="Padding">
                        <OnPlatform x:TypeArguments="Thickness">
                            <On Platform="iOS">20,0,20,0</On>
                            <On Platform="Default">0</On>
                        </OnPlatform>
                    </Setter>
                </Style>
    

    Thanks @XavierPerseguers

Sign In or Register to comment.