共用方式為


Device Class

Definition

A utility class to interact with the current Device/Platform.

public static class Device
type Device = class
Inheritance
System.Object
Device

Fields

Android

The string "Android", representing the Android operating system.

GTK

The string "GTK", representing the Linux operating system.

info

For internal use by the Xamarin.Forms platform.

iOS

The string "iOS", representing the iOS operating system.

macOS

The string "macOS", representing the macOS operating system.

Tizen

The string "Tizen", representing the Tizen operating system.

UWP

The string "UWP", representing the UWP operating system.

WPF

The string "WPF", representing the Windows Presentation Foundation framework.

Properties

Flags

Gets a list of custom flags that were set on the device before Xamarin.Forms was initialized.

FlowDirection

Gets the flow direction on the device.

Idiom

Gets the kind of device that Xamarin.Forms is currently working on.

Info

For internal use by the Xamarin.Forms platform.

IsInvokeRequired

For internal use by the Xamarin.Forms platform.

OS
Obsolete.

Gets the TargetPlatform indicating the OS Xamarin.Forms is working on.

PlatformInvalidator
PlatformServices

For internal use by the Xamarin.Forms platform.

RuntimePlatform

Gets the kind of device that Xamarin.Forms is currently working on.

Methods

BeginInvokeOnMainThread(Action)

Invokes an Action on the device main (UI) thread.

GetAssemblies()

For internal use by the Xamarin.Forms platform.

GetMainThreadSynchronizationContextAsync()

Returns the current System.Threading.SynchronizationContext from the main thread.

GetNamedColor(String)
GetNamedSize(NamedSize, Element)

Returns a double that represents a font size that corresponds to size on targetElement.

GetNamedSize(NamedSize, Type, Boolean)

For internal use by the Xamarin.Forms platform.

GetNamedSize(NamedSize, Type)

Returns a double that represents the named size for the font that is used on the element on the native platform.

Invalidate(VisualElement)
InvokeOnMainThreadAsync(Action)

Invokes an Action on the device main (UI) thread.

InvokeOnMainThreadAsync(Func<Task>)

Invokes a Func on the device main (UI) thread.

InvokeOnMainThreadAsync<T>(Func<T>)

Invokes a Func on the device main (UI) thread.

InvokeOnMainThreadAsync<T>(Func<Task<T>>)

Invokes a Func on the device main (UI) thread.

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.

OpenUri(Uri)
Obsolete.

Request the device to open the Uri.

SetFlags(IReadOnlyList<String>)

Sets a list of custom flags on the device.

SetFlowDirection(FlowDirection)

Sets the flow direction on the device.

SetIdiom(TargetIdiom)

For internal use by the Xamarin.Forms platform.

SetTargetIdiom(TargetIdiom)

For internal use by the Xamarin.Forms platform.

StartTimer(TimeSpan, Func<Boolean>)

Starts a recurring timer using the device clock capabilities.

Applies to