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
Properties
AllowReinitialize
#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
#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.
Example:
using (platform.Context)
{
// do some stuff with the specified platform
}Detect
#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
#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
#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
#Gets a value indicating whether this platform is based on Xamarin.Android.
Value:
true if this platform is android; otherwise, false.IsDesktop
#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.
Value:
true if this is a desktop platform; otherwise, false.IsGtk
#Gets a value indicating whether this platform is based on GTK# (2 or 3)
Value:
true if this platform is gtk; otherwise, false.IsIos
#Gets a value indicating whether this platform is based on Xamarin.iOS
Value:
true if this platform is ios; otherwise, false.IsMac
#Gets a value indicating whether this platform is a mac based platform (MonoMac/MacOS)
Value:
true if this platform is mac; otherwise, false.IsMobile
#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.
Value:
true if this instance is mobile; otherwise, false.IsValid
#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.
Value:
true if this platform is valid and can be run; otherwise, false.IsWinForms
#Gets a value indicating whether this platform is based on Windows Forms
Value:
true if this platform is window forms; otherwise, false.IsWpf
#Gets a value indicating whether this platform is based on WPF
Value:
true if this platform is wpf; otherwise, false.Methods
Add
#Add the specified type and instantiator.
Parameters:
| 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>
#Add the
instantiator for the specified handler type of TParameters:
| instantiator (Func<T>) | Instantiator to create an instance of the handler |
Cache<TKey, TValue>
#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.
Parameters:
| cacheKey (object) | Unique cache key to load the cache instance |
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.Parameters:
| platform (Platform = null) | Platform to copy, or null to copy the global (first) platform. |
Returns: A new copy of the platform instance
Exceptions:
| ArgumentNullException | Throws if platform is null, and, if the global instance has not been created. |
Create
#Creates a new instance of the handler of the specified type
Parameters:
| type (Type) | Type of handler to create |
Returns: A new instance of a handler
Create<T>
#public T Create<T>()
Creates a new instance of the handler of the specified type of
TRemarks: This extension should be used when creating instances of a fixed type.
Returns: A new instance of a handler
Find
#Find the delegate to create instances of the specified
typeParameters:
| type (Type) | Type of the handler interface to get the instantiator for (usually derived from Widget.IHandler or another type) |
Find<T>
#Finds the delegate to create instances of the specified type
Returns: The delegate to use to create instances of the specified type
Get
#Gets the generator of the specified type
Parameters:
| generatorType (string) | Type of the generator to get |
Returns: An instance of a Generator of the specified type, or null if it cannot be loaded
Initialize
#Initializes the specified
platform as the current generator, for the current threadRemarks: This is called automatically by the Application when it is constructed
Parameters:
| platform (Platform) | Generator to set as the current generator |
Initialize
#Initialize the generator with the specified
platformType as the current generatorParameters:
| platformType (string) | Type of the generator to set as the current generator |
Invoke<T>
#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.
Parameters:
| action (Func<T>) | Action to execute. |
Example:
var mycontrol = MyPlatform.Invoke(() => new MyControl());Invoke
#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.
Parameters:
| action (Action) | Action to execute. |
LoadAssembly
#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.Parameters:
| assembly (Assembly) | Assembly to load the extensions for. |
LoadAssembly
#Loads the extensions specified by the assembly attribute PlatformExtensionAttribute.
Parameters:
| assemblyName (string) | Name of the assembly to load the extensions for. |
See Also: LoadAssembly(Assembly)
OnHandlerCreated
#Handles the WidgetCreated event
Parameters:
| e (HandlerCreatedEventArgs) | Arguments for the event |
OnWidgetCreated
#Handles the WidgetCreated event
Parameters:
| e (WidgetCreatedEventArgs) | Arguments for the event |
Supports
#Gets a value indicating that the specified
type is supported by this platformParameters:
| type (Type) | Type of the handler or class with HandlerAttribute to test for. |
Returns: true if the specified type is supported, false otherwise
Supports<T>
#Gets a value indicating that the specified type is supported by this platform
Returns: true if the specified type is supported, false otherwise