共用方式為


Device.OnPlatform 方法

定義

多載

OnPlatform(Action, Action, Action, Action)
已淘汰.

根據 Xamarin.Forms 執行所在的 TargetPlatform,執行不同的動作。

OnPlatform<T>(T, T, T)
已淘汰.

根據 Xamarin.Forms 執行所在的 TargetPlatform,傳回不同的值。

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
System.Action

(選用) 要在 iOS 上執行的動作。

Android
System.Action

(選用) 要在 Android 上執行的動作。

WinPhone
System.Action

(選用) 要在 WinPhone 上執行的動作。

Default
System.Action

(選用) 未針對目前作業系統提供任何動作時所要執行的動作。

屬性
System.ComponentModel.EditorBrowsableAttribute System.ObsoleteAttribute

備註

此範例示範如何在單一 OS 上變更標籤的字型。

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.

根據 Xamarin.Forms 執行所在的 TargetPlatform,傳回不同的值。

[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 的值。

屬性
System.ComponentModel.EditorBrowsableAttribute System.ObsoleteAttribute

備註

此範例示範如何針對不同操作系統上的 Button 使用不同的高度。

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

適用於