Starting point for any UI application
Remarks: This class is used to start an application. When you are using Eto.Forms within an existing application, you can use the Attach(object) method.
Constructors
Application
#Initializes a new instance of the Application class with the specified platform
Parameters:
| platform (Platform) | Platform to run the application |
Application
#Initializes a new instance of the Application class with the specified platform type
Fields
Identifier for the ThemeChanged event.
Properties
AlternateModifier
#Gets the alternate modifier for shortcuts.
Remarks: This is usually the Keys.Alt key.
Value: The alternate modifier.
BadgeLabel
#Gets or sets the badge label on the application icon in the dock, taskbar, etc.
Remarks: This allows you to specify the text to show as a label to notify the state of your application to the user. Note that some platforms (iOS) only support numeric badge labels.
Value: The badge label.
CommonModifier
#Gets the common modifier for shortcuts.
Remarks: On Windows/Linux, this will typically return Keys.Control, and on OS X this will be Keys.Application (the command key).
Value: The common modifier.
Remarks: This can sometimes be useful to get the platform-specific object. Some handlers may not have any backing object for its functionality, so this may be null. It is more preferred to use the Widget.Handler and cast that to the platform-specific handler class which can give you additional methods and helpers to do common tasks. For example, the Application object's handler for OS X has a AddFullScreenMenuItem property to specify if you want full screen support in your app.
IsDisposed
Gets or sets a value indicating whether this Widget has been disposed.
Remarks: When the widget is disposed, it can no longer be used.
Value:
true if this instance has been disposed; otherwise, false.Gets a value indicating that the current thread is on the UI thread for this Application instance.
MainForm
#Gets or sets the main form for your application.
Remarks: When you set this to your main application form, it will get standard platform behaviour applied, such as quitting the application when it is closed (on windows, linux), or showing the main form on OS X when clicking the application icon if it has been hidden/closed. Setting this is optional, however you must then manually call Quit() when you want your application to quit in that case.
Value: The main form for your application.
NativeHandle
public nint NativeHandle { get; }
Gets the native platform-specific handle for integration purposes
Value: The native handle.
inherited fromWidget
Remarks: This gets set to the current Platform.Instance during the construction of the object
QuitIsSupported
#Gets a value indicating whether this Application supports the Quit() operation.
Value:
true if quit is supported; otherwise, false.Remarks: Styles allow you to attach custom platform-specific logic to a widget. In your platform-specific assembly, use Add{H} to add the style logic with the same id.
Example:
// in your UI
var control = new Button { Style = "mystyle" };
// in your platform assembly
using Eto.Mac.Forms.Controls;
Styles.AddHandler<ButtonHandler>("mystyle", handler => {
// this is where you can use handler.Control to set properties, handle events, etc.
handler.Control.BezelStyle = NSBezelStyle.SmallSquare;
});Gets or sets the current visual theme of the application.
Remarks: Changing this value will update the application's visual appearance and raise the ThemeChanged event. Use Themes.AllThemes to get available themes. Note that not all platforms fully support changing themes at runtime, in particular WinForms. In this case, you need to set the theme before creating any controls.
UIThreadCheckMode
#Gets or sets the UI thread check mode which can be used to troubleshoot or ensure that all UI code is executed in the UI thread.
Value: The current thread check mode
Windows
#Gets an enumeration of windows currently open in the application.
Value: The enumeration of open windows.
Methods
AsyncInvoke
#Invoke the action asynchronously on the UI thread
Remarks: This will return immediately and queue the action to be executed on the UI thread, regardless on whether the current thread is the UI thread.
Parameters:
| action (Action) | Action to queue on the UI thread. |
Attach
#Attach the application to an already-running native application with the same platform.
Parameters:
| context (object = null) | Context of the application |
Dispose
public void Dispose()
Disposes of this widget, supressing the finalizer
Parameters:
| disposing (bool) | True if the caller called Widget.Dispose() manually, false if being called from a finalizer |
GetCallback
#Gets an instance of an object used to perform callbacks to the widget from handler implementations
Returns: The callback instance to use for this widget
Overrides: Widget.GetCallback
Initialize
protected void Initialize()
Initializes the widget handler
Remarks: This is typically called from the constructor after all of the logic is completed to construct the object. If your handler interface has the AutoInitializeAttribute set to false, then you are responsible for calling this method in your constructor after calling the creation method on your custom handler.
Invoke<T>
#Invoke the specified function on the UI thread returning its value after the execution is complete.
Remarks: Use this method when you want to return values from the UI in a worker thread.
Parameters:
| func (Func<T>) | Function to execute and return the value on the UI thread. |
Invoke
#Invoke the specified action on the UI thread, blocking the current execution until it is complete.
Remarks: Use this method when you want to perform changes to the UI from a worker thread, and return when the changes are complete.
Parameters:
| action (Action) | Action to invoke |
InvokeAsync
#Invokes the specified action on the UI thread asynchronously with a Task.
Parameters:
| action (Action) | Action to execute. |
Returns: The task that is used to await when the action is completed.
InvokeAsync<T>
#Invokes the specified function on the UI thread asynchronously and return the result in a Task.
Parameters:
| func (Func<T>) | Function to execute and return the value. |
Returns: The task that returns the result of the function.
Localize
#Localizes the specified text for the current locale, or provide alternative text for system supplied strings.
Remarks: This depends on your custom implementation for the LocalizeString event. You can provide your own localization for system-supplied strings or change the strings to your own liking.
Returns: The localized text.
OnInitialized
#Raises the Initialized event.
Remarks: This is where any of your startup code should be placed, such as creating the main form and showing it. If you are not subclassing Application, you can handle the Initialized event instead.
Parameters:
| e (EventArgs) | Event arguments. |
OnLocalizeString
#Triggers the LocalizeString event.
Parameters:
| e (LocalizeEventArgs) | Event arguments for localization |
inherited fromWidget
Open
#Open the specified file or url with its associated application.
Parameters:
| url (string) | url or file path to open |
Quit
#public void Quit()
Quits the application
Remarks: This will call the Terminating event before terminating the application.
Run
#Runs the application with the specified
dialog and begins the main loop.Remarks: When the dialog is closed, the application will exit.
Parameters:
| dialog (Dialog) | Dialog to show for the application. |
Run
#Runs the application with the specified
mainForm and begins the main loop.RunIteration
#public void RunIteration()
Advanced. Runs an iteration of the main UI loop when you are blocking the UI thread with logic.
Remarks: This is not recommended to use and you should use asynchronous calls instead via Task.Run or threads.
ToString
Gets a string that represents the current object with its ID if specified.
Returns: A string value indicating the type and ID (if specified) of this widget.
Overrides: Object.ToString
Events
Initialized
#Occurs when the application is initialized
Remarks: This is where any of your startup code should be placed, such as creating the main form and showing it. If subclassing Application, you can override OnInitialized(EventArgs) instead.
IsActiveChanged
#Occurs when the IsActive property is changed, which tracks whether the application is currently active or not.
LocalizeString
#Event to handle when a string needs to be localized
Remarks: This can be used by some controls (e.g. AboutDialog and MenuBar on some platforms. You can use this event or override OnLocalizeString(LocalizeEventArgs) to provide your own implementation for localizing system-supplied strings to other languages.
NotificationActivated
#Occurs when a notification is clicked by the user that was previously displayed.
Remarks: To send a notification, use Notification. The NotificationEventArgs.ID and NotificationEventArgs.UserData should be used to determine what action to perform when the user clicks on the notification. These parameters are set when creating the Notification
inherited fromWidget
Occurs when the Theme has changed.