Device.OnPlatform Method

Definition

Overloads

OnPlatform(Action, Action, Action, Action)
Obsolete.

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

OnPlatform<T>(T, T, T)
Obsolete.

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

OnPlatform(Action, Action, Action, Action)

Caution

OnPlatform is obsolete as of version 2.3.4. Please use 'switch (Device.RuntimePlatform)' instead.

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

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

Parameters

iOS
Action

(optional) The Action to execute on iOS.

Android
Action

(optional) The Action to execute on Android.

WinPhone
Action

(optional) The Action to execute on WinPhone.

Default
Action

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

Attributes

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));

Applies to

OnPlatform<T>(T, T, T)

Caution

OnPlatform<> (generic) is obsolete as of version 2.3.4. Please use 'switch (Device.RuntimePlatform)' instead.

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

[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
[System.Obsolete("OnPlatform<> (generic) is obsolete as of version 2.3.4. Please use 'switch (Device.RuntimePlatform)' instead.")]
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

The value for iOS.

Android
T

The value for Android.

WinPhone
T

The value for WinPhone.

Returns

T

The value for the current OS.

Attributes

Remarks

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

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

Applies to