How do we provide Platform specific styling or values in XAML?

Technology CommunityCategory: XamarinHow do we provide Platform specific styling or values in XAML?
VietMX Staff asked 3 years ago

We can use OnPlatform Tag in XAML to achieve this. OnPlatform Tag provides a way to declare platform specific values to some properties directly into XAML. For example if we want to provide different font size to a Button for each platform, it can be achieved like:

<Button VerticalOptions="CenterAndExpand" Text="Save"\>
    <Button.FontSize>
        <OnPlatform x:TypeArguments="x:Double"\>
            <On Platform="iOS"\>15</On\>
            <On Platform="Android"\>13</On\>
            <On Platform="WinPhone"\>14</On\>
        </OnPlatform\>
    </Button.FontSize\>
</Button\>