Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New OnPlatform/OnIdiom XAML Extension - Usage for Margin Thickness

In Xamarin.Forms 3.2.0, Xamarin Forms introduced new New OnPlatform/OnIdiom XAML Extension

As per the blog we can re-write the below code,

<Button Text="Extensions" BackgroundColor="Black" TextColor="White">
<Button.HeightRequest>
     <OnPlatform x:TypeArguments="x:Double" Default="40">
        <On Platform="iOS" Value="60"/>
        <On Platform="Android" Value="80"/>
    </OnPlatform>
</Button.HeightRequest>

with the new extension.

<Button Text="Extensions" BackgroundColor="Black" TextColor="White" 
    HeightRequest="{OnPlatform iOS=60, Android=80, Default=40}"/>

Here my doubt is how I can reuse the same OnIdiom XAML Extension for Margin / Thickness.

like image 718
StezPet Avatar asked Oct 21 '18 10:10

StezPet


1 Answers

You should be able to do it like this: <Button Margin="{OnPlatform Android='10,5,10,0', iOS='10,20,10,0'}" />

It's up to you which syntax you like more!

like image 197
Gerald Versluis Avatar answered Oct 06 '22 10:10

Gerald Versluis