Device.OnPlatform deprecated

switch (Device.RuntimePlatform)
        {
            case Device.iOS:
                    Padding = new Thickness(5, 5, 5, 0);
                    break;

            default:
                    Padding = new Thickness(5, 5, 5, 0);
                    break;
         }

2016 was the year this method became deprecated.

You're supposed to use a switch statement to determine the OS.

switch(Device.RuntimePlatform)
{
    case Device.iOS:
      return new Thickness(5, 5, 5, 0)
    default:
      return new Thickness(5, 5, 5, 0)
 }

You can of course wrap this inside a function which will do the same job as you wished to do with Device.OnPlatform, but instead of calling Device.OnPlatform you'll call your own function.


In case someone has the same problem in a XAML file, this is way to get around the deprecated message:

<ContentPage.Padding>
    <OnPlatform x:TypeArguments="Thickness">
        <On Platform="iOs">0,20,0,0</On>
    </OnPlatform>
</ContentPage.Padding>

Tags:

C#

Xamarin