Hey there.
<OnPlatform x:TypeArguments="Thickness" iOS="10" Android="10"/>
is deprecated. As far as I know this should be used:
<OnPlatform x:TypeArguments="Thickness"> <On Platform="iOS">10</On> <On Platform="Android">10</On> </OnPlatform>
Same here. This is obsolete:
Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0);
instead a switch case similar to this should be used:
int tVal; switch(Device.RuntimePlatform) { case Device.iOS: tVal = 10; break; default: tVal = 10; break; } Padding = new Thickness(0, tVal, 0, 0);
And I don´t understand why. The deprecated/obsolete way is shorter. Is this performance related or something else??
That syntax was deprecated back in Xamarin Forms 2.3-2.4.0 (Can't remember which), the main reason was to make it less verbose in XAML and make it less breaking for platform changes.
<Entry.Margin> <OnPlatform x:TypeArguments="Thickness" Default="0,0,0,0"> <On Platform="iOS,Android">0,4,2,4</On> </OnPlatform> </Entry.Margin>
The downside was code based assignments need switches but with the amount of platforms increasing significantly since the deprecated interface the change was needed.
In Xamarin Forms 3.2 upwards it much nicer with new markup extensions
HeightRequest="{x:OnPlatform Android=38,iOS=36,UWP=38,Default=40}"
You can always write your own code extension method if you don't expect to add additional platforms
Answers
@axbeit
That syntax was deprecated back in Xamarin Forms 2.3-2.4.0 (Can't remember which), the main reason was to make it less verbose in XAML and make it less breaking for platform changes.
The downside was code based assignments need switches but with the amount of platforms increasing significantly since the deprecated interface the change was needed.
In Xamarin Forms 3.2 upwards it much nicer with new markup extensions
You can always write your own code extension method if you don't expect to add additional platforms
Hey, how make I this with OnIdiom?
