Device.OnPlatform 方法

定义

重载

OnPlatform(Action, Action, Action, Action)
已过时。

根据 Xamarin.Forms 正在处理的 TargetPlatform 执行不同的操作。

OnPlatform<T>(T, T, T)
已过时。

根据 TargetPlatform Xamarin.Forms 正在处理的内容返回不同的值。

OnPlatform(Action, Action, Action, Action)

注意

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

根据 Xamarin.Forms 正在处理的 TargetPlatform 执行不同的操作。

[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

参数

iOS
Action

(可选)要在 iOS 上执行的操作。

Android
Action

(可选)要在 Android 上执行的操作。

WinPhone
Action

(可选)要在 WinPhone 上执行的操作。

Default
Action

(可选)没有为当前操作系统提供操作时要执行的操作。

属性

注解

此示例演示如何在单个 OS 上更改 Label 的字体。

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

适用于

OnPlatform<T>(T, T, T)

注意

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

根据 TargetPlatform Xamarin.Forms 正在处理的内容返回不同的值。

[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

类型参数

T

要返回的值的类型。

参数

iOS
T

iOS 的值。

Android
T

Android 的值。

WinPhone
T

WinPhone 的值。

返回

T

当前操作系统的值。

属性

注解

此示例演示如何在不同 OS 上为按钮使用不同的高度。

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

适用于