Xamarin.Forms Guides | Samples

Xamarin.Forms.Device.OnPlatform Method

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

Syntax

[System.Obsolete("Use switch(RuntimePlatform) instead.")]
public static Void OnPlatform (Action iOS, Action Android, Action WinPhone, Action Default)

Parameters

iOS
(optional) The Action to execute on iOS.
Android
(optional) The Action to execute on Android.
WinPhone
(optional) The Action to execute on WinPhone.
Default
(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.

C# Example

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

Requirements

Namespace: Xamarin.Forms
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions: 1.0.0.0, 1.1.0.0, 1.2.0.0, 1.3.0.0, 1.4.0.0, 1.5.0.0, 2.0.0.0