Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

How use Device.RuntimePlatform in XAML??

$
0
0

Device.OnPlatform is marked Obsolete: https://docs.microsoft.com/en-us/dotnet/api/Xamarin.Forms.Device.OnPlatform?view=xamarin-forms#Xamarin_Forms_Device_OnPlatform_System_Action_System_Action_System_Action_System_Action_

Docs claim the replacement is Device.RuntimePlatform. So I try to find how to use it. ALL I find is C# code. Huh?

For example, on https://xamarinhelp.com/xamarin-forms-onplatform-runtimeplatform/
@AdamPedley shows XAML using OnPlatform:

    <OnPlatform x:TypeArguments="Thickness">
        <On Platform="Android, UWP">0</On>
        <On Platform="iOS">0,20,0,0</On>
    </OnPlatform>

And then the replacement which is in C#:

switch(Device.RuntimePlatform)
{
case Device.iOS:
    this.Padding = new Thickness(0,20,0,0);
    break;
case Device.Android:
case Device.UWP:   
case Device.macOS:
default:
    // This is just an example. You wouldn't actually need to do this, since Padding is already 0 by default.
    this.Padding = new Thickness(0);
    break;
}

??? That isn't a replacement for a feature that works in XAML - that's C# code.

Explanation please. Is this useable in XAML? Will be in the future?


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>