Device.OnPlatform Device.OnPlatform Method

Definition

Overloads

OnPlatform(Action, Action, Action, Action) OnPlatform(Action, Action, Action, Action)

Executes different Actions depending on the TargetPlatform that Xamarin.Forms is working on.

OnPlatform<T>(T, T, T) OnPlatform<T>(T, T, T)

Returns different values depending on the TargetPlatform Xamarin.Forms is working on.

OnPlatform(Action, Action, Action, Action) OnPlatform(Action, Action, Action, Action)

Warning

This API is now obsolete.

Executes different Actions depending on the TargetPlatform that Xamarin.Forms is working on.

[System.Obsolete("OnPlatform is obsolete as of version 2.3.4. Please use 'switch (Device.RuntimePlatform)' instead.")]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public static void OnPlatform (Action iOS = null, Action Android = null, Action WinPhone = null, Action Default = null);
static member OnPlatform : Action * Action * Action * Action -> unit

Parameters

iOS
Action Action

(optional) The Action to execute on iOS.

Android
Action Action

(optional) The Action to execute on Android.

WinPhone
Action Action

(optional) The Action to execute on WinPhone.

Default
Action Action

(optional) The Action to execute if no Action was provided for the current OS.

Remarks

This example shows how to change the font of a Label on a single OS.


Device.OnPlatform (iOS: () => label.Font = Font.OfSize ("HelveticaNeue-UltraLight", NamedSize.Large));

OnPlatform<T>(T, T, T) OnPlatform<T>(T, T, T)

Warning

This API is now obsolete.

Returns different values depending on the TargetPlatform Xamarin.Forms is working on.

[System.Obsolete("OnPlatform<> (generic) is obsolete as of version 2.3.4. Please use 'switch (Device.RuntimePlatform)' instead.")]
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public static T OnPlatform<T> (T iOS, T Android, T WinPhone);
static member OnPlatform : 'T * 'T * 'T -> 'T

Type Parameters

T

The type of the value to be returned.

Parameters

iOS
T T

The value for iOS.

Android
T T

The value for Android.

WinPhone
T T

The value for WinPhone.

Returns

T T

The value for the current OS.

Remarks

This example shows how to use different heights for a Button on different OS.


button.HeightRequest = Device.OnPlatform (20,30,30);

Applies to