Platform

References
public abstract class Platform
Base platform class
Remarks: This class takes care of creating the platform-specific implementations of each control. All controls the platform can handle should be added using Add<T>(Func<T>).

Constructors

Platform

#
protected Platform()
Initializes a new instance of the Platform class

Properties

AllowReinitialize

#
public static bool AllowReinitialize { get; set; }
Gets or sets a value indicating that the platform should allow reinitialization.
Remarks: When false, prevents incorrect logic that may create multiple instances of Application or Platform in the same thread which can causes issues where handlers are no longer registered, etc. Multiple instances should still be able to be created in separate threads (for platforms that support it) when this is false.

Context

#
public IDisposable Context { get; }
Gets an object to wrap in the platform's context, when using multiple platforms.
Remarks: This sets this platform as current, and reverts back to the previous platform when disposed. This value may be null.
using (platform.Context)
{
	// do some stuff with the specified platform
}

Detect

#
public static Platform Detect { get; }
Returns the current generator, or detects the generator to use if no current generator is set.
Remarks: This detects the platform to use based on the generator assemblies available and the current OS. For windows, it will prefer WPF to Windows Forms. Mac OS X will prefer the Mac platform. Other unix-based platforms will prefer GTK.

ID

#
public abstract string ID { get; }
Gets the ID of this platform
Remarks: The platform ID can be used to determine which platform is currently in use. The platform does not necessarily correspond to the OS that it is running on, as for example the GTK platform can run on OS X and Windows.

Instance

#
public static Platform Instance { get; }
Gets the platform for the current thread
Remarks: Typically you'd have only one platform active at a time, and this holds an instance to that value. The current platform is set automatically by the Application class when it is initially created. This will return a different value for each thread, so if you have multiple platforms running (e.g. GTK + Mac for OS X), then this will allow for that. This will be used when creating controls. To create controls on a different platform outside of its own thread, use the Context property.

IsAndroid

#
public virtual bool IsAndroid { get; }
Gets a value indicating whether this platform is based on Xamarin.Android.

IsDesktop

#
public virtual bool IsDesktop { get; }
Gets a value indicating whether this is a desktop platform. This includes Mac, Gtk, WinForms, Wpf, Direct2D.
Remarks: A desktop platform is usually used via mouse & keyboard, and can have complex user interface elements.
true if this is a desktop platform; otherwise, false.

IsGtk

#
public virtual bool IsGtk { get; }
Gets a value indicating whether this platform is based on GTK# (2 or 3)

IsIos

#
public virtual bool IsIos { get; }
Gets a value indicating whether this platform is based on Xamarin.iOS

IsMac

#
public virtual bool IsMac { get; }
Gets a value indicating whether this platform is a mac based platform (MonoMac/MacOS)

IsMobile

#
public virtual bool IsMobile { get; }
Gets a value indicating whether this is a mobile platform. This includes iOS, Android, and WinRT.
Remarks: A mobile platform is usually touch friendly, and have a simpler interface.
true if this instance is mobile; otherwise, false.

IsValid

#
public virtual bool IsValid { get; }
Gets a value indicating that this platform is valid on the running device
Remarks: This is used in platform detection to ensure that the correct platform is loaded. For example, the Mac platforms are only valid when run in an .app bundle.
true if this platform is valid and can be run; otherwise, false.

IsWinForms

#
public virtual bool IsWinForms { get; }
Gets a value indicating whether this platform is based on Windows Forms

IsWpf

#
public virtual bool IsWpf { get; }
Gets a value indicating whether this platform is based on WPF

SupportedFeatures

#
public virtual PlatformFeatures SupportedFeatures { get; }
Gets the supported features of the platform.

Methods

Add

#
public void Add(Type type, Func<object> instantiator)
Add the specified type and instantiator.
type (Type)Type of the handler (usually an interface derived from Widget.IHandler)
instantiator (Func<object>)Instantiator to create an instance of the handler

Add<T>

#
public void Add<T>(Func<T> instantiator)
Add the instantiator for the specified handler type of T
instantiator (Func<T>)Instantiator to create an instance of the handler

Cache<TKey, TValue>

#
public Dictionary<TKey, TValue> Cache<TKey, TValue>(object cacheKey)
Gets a shared cache dictionary
Remarks: This is used to cache things like brushes and pens, but can also be used to cache other things for your application's use.
cacheKey (object)Unique cache key to load the cache instance

Copy

#Since v2.10
public static Platform Copy(Platform platform = null)
Creates a copy of the specified platform, or the global instance if one is created.
Remarks: This can be used to create a plaform instance for a secondary thread to show UI. It requires that the platform has a public constructor with no parameters. For example, you can initialize Eto for use in a separate thread (for platforms that support it) like so:
var app = new Application(Eto.Platform.Copy());
app.Attach();

var dialog = new Dialog();
dialog.ShowModal();
Note that Application.Instance will return the application instance for the current thread. If you want to invoke on the secondary thread when you already have a main thread, you will have to keep an instance of the new application instance manually and call Invoke/AsyncInvoke on that instance.
platform (Platform = null)Platform to copy, or null to copy the global (first) platform.
A new copy of the platform instance
ArgumentNullExceptionThrows if platform is null, and, if the global instance has not been created.

Create

#
public object Create(Type type)
Creates a new instance of the handler of the specified type
type (Type)Type of handler to create
A new instance of a handler

Create<T>

#
public T Create<T>()
Creates a new instance of the handler of the specified type of T
Remarks: This extension should be used when creating instances of a fixed type.
A new instance of a handler

CreateShared

#
public object CreateShared(Type type)
Creates a shared singleton instance of the specified type of type
type (Type)The type of handler to get a shared instance for
The shared instance of a handler of the given type, or a new instance if not already created

CreateShared<T>

#
public T CreateShared<T>()
Creates a shared singleton instance of the specified type of T
Remarks: This extension should be used when creating shared instances of a fixed type.
The shared instance of a handler of the given type, or a new instance if not already created

Find

#
public Func<object> Find(Type type)
Find the delegate to create instances of the specified type
type (Type)Type of the handler interface to get the instantiator for (usually derived from Widget.IHandler or another type)

Find<T>

#
public Func<T> Find<T>()
Finds the delegate to create instances of the specified type
The delegate to use to create instances of the specified type

Get

#
public static Platform Get(string generatorType)
Gets the generator of the specified type
generatorType (string)Type of the generator to get
An instance of a Generator of the specified type, or null if it cannot be loaded

Initialize

#
public static void Initialize(Platform platform)
Initializes the specified platform as the current generator, for the current thread
Remarks: This is called automatically by the Application when it is constructed
platform (Platform)Generator to set as the current generator

Initialize

#
public static void Initialize(string platformType)
Initialize the generator with the specified platformType as the current generator
platformType (string)Type of the generator to set as the current generator

Invoke<T>

#
public T Invoke<T>(Func<T> action)
Invoke the specified function within the context of this platform, returning its value.
Remarks: This is useful when you are using multiple platforms at the same time, and gives you an easy way to execute code within the context of this platform, and return its value.
action (Func<T>)Action to execute.
var mycontrol = MyPlatform.Invoke(() => new MyControl());

Invoke

#
public void Invoke(Action action)
Invoke the specified action within the context of this platform
Remarks: This is useful when you are using multiple platforms at the same time, and gives you an easy way to execute code within the context of this platform.
action (Action)Action to execute.

LoadAssembly

#
public void LoadAssembly(Assembly assembly)
Loads the extensions specified by the assembly attribute PlatformExtensionAttribute.
Remarks: This is useful for 3rd party libraries and when defining your own custom controls. This method is called automatically on the same assembly of a custom control when its handler cannot be found. It will also be called for the same assembly with the prefix of the platform ID. For example, if MyControl was declared in MyControls.dll, then Eto will automatically also load MyControls.Wpf.dll for the Wpf platform, and MyControls.MacOS.dll for the MacOS platform, etc. Use ExportHandlerAttribute and ExportInitializerAttribute to register handlers with the platform when the assembly is loaded or perform other logic.
assembly (Assembly)Assembly to load the extensions for.

LoadAssembly

#
public void LoadAssembly(string assemblyName)
Loads the extensions specified by the assembly attribute PlatformExtensionAttribute.
assemblyName (string)Name of the assembly to load the extensions for.

OnHandlerCreated

#
protected virtual void OnHandlerCreated(HandlerCreatedEventArgs e)
Handles the WidgetCreated event

OnWidgetCreated

#
protected virtual void OnWidgetCreated(WidgetCreatedEventArgs e)
Handles the WidgetCreated event

Supports

#
public virtual bool Supports(Type type)
Gets a value indicating that the specified type is supported by this platform
type (Type)Type of the handler or class with HandlerAttribute to test for.
true if the specified type is supported, false otherwise

Supports<T>

#
public bool Supports<T>()
Gets a value indicating that the specified type is supported by this platform

ThreadStart

#
public virtual IDisposable ThreadStart()
Used at the start of your custom threads

Events

HandlerCreated

#
public event EventHandler<HandlerCreatedEventArgs> HandlerCreated
Event to handle when widgets are created by this platform

WidgetCreated

#
public event EventHandler<WidgetCreatedEventArgs> WidgetCreated
Event to handle when widgets are created by this platform