Application

WidgetReferences
[Handler(Application.IHandler)] public class Application : Widget
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

#
public Application(Platform platform)
Initializes a new instance of the Application class with the specified platform

Application

#
public Application(string platformType)
Initializes a new instance of the Application class with the specified platform type
platformType (string)Platform type to initialize this application with
Platforms

Fields

IsActiveChangedEvent

#
public const string IsActiveChangedEvent = "Application.IsActiveChanged"
Identifier for handlers when attaching the IsActiveChanged event

NotificationActivatedEvent

#
public const string NotificationActivatedEvent = "Application.NotificationActivated"
Identifier for handlers when attaching the NotificationActivated event

TerminatingEvent

#
public const string TerminatingEvent = "Application.Terminating"
Identifier for handlers when attaching the Terminating event

ThemeChangedEvent

#Since v2.12
public const string ThemeChangedEvent = "Application.ThemeChanged"
Identifier for the ThemeChanged event.

UnhandledExceptionEvent

#
public const string UnhandledExceptionEvent = "Application.UnhandledException"
Identifier for handlers when attaching the UnhandledException event

Properties

AlternateModifier

#
public Keys AlternateModifier { get; }
Gets the alternate modifier for shortcuts.

BadgeLabel

#
public string BadgeLabel { get; set; }
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.
The badge label.

CommonModifier

#
public Keys CommonModifier { get; }
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).
The common modifier.

ControlObject

public object ControlObject { get; }
Gets the instance of the platform-specific object
inherited fromWidget
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.

Handler

public object Handler { get; }
Gets the platform-specific handler for this widget
inherited fromWidget

Instance

#
public static Application Instance { get; }
Gets the current application instance

IsActive

#
public bool IsActive { get; }
Gets a value indicating that the application is currently the active application.

IsDisposed

public bool IsDisposed { get; }
Gets or sets a value indicating whether this Widget has been disposed.
inherited fromWidget
Remarks: When the widget is disposed, it can no longer be used.
true if this instance has been disposed; otherwise, false.

IsUIThread

#Since v2.10
public bool IsUIThread { get; }
Gets a value indicating that the current thread is on the UI thread for this Application instance.

MainForm

#
public Form MainForm { get; set; }
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.
The main form for your application.

Name

#
public string Name { get; set; }
Gets or sets the name of your application

NativeHandle

public nint NativeHandle { get; }
Gets the native platform-specific handle for integration purposes
inherited fromWidget

Platform

public Platform Platform { get; }
Gets the platform that was used to create the Widget.Handler for this widget
inherited fromWidget
Remarks: This gets set to the current Platform.Instance during the construction of the object

Properties

public PropertyStore Properties { get; }
Gets the dictionary of properties for this widget
inherited fromWidget

QuitIsSupported

#
public bool QuitIsSupported { get; }
Gets a value indicating whether this Application supports the Quit() operation.

Style

public string Style { get; set; }
Gets or sets the style of this widget
inherited fromWidget
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.
// 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;
});

Theme

#Since v2.12
public Theme Theme { get; set; }
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

#
[DefaultValue(UIThreadCheckMode.Warning)] public UIThreadCheckMode UIThreadCheckMode { get; set; }
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.

Windows

#
public IEnumerable<Window> Windows { get; }
Gets an enumeration of windows currently open in the application.

Methods

AsyncInvoke

#
public virtual void AsyncInvoke(Action action)
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.
action (Action)Action to queue on the UI thread.

Attach

#
public virtual Application Attach(object context = null)
Attach the application to an already-running native application with the same platform.

Dispose

protected virtual void Dispose(bool disposing)
Handles the disposal of this widget
inherited fromWidget
disposing (bool)True if the caller called Widget.Dispose() manually, false if being called from a finalizer

EnsureUIThread

#
public void EnsureUIThread()
Ensures the current thread is the main/UI thread

GetCallback

#
protected override object GetCallback()
Gets an instance of an object used to perform callbacks to the widget from handler implementations

Initialize

protected void Initialize()
Initializes the widget handler
inherited fromWidget
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>

#
public T Invoke<T>(Func<T> func)
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.
func (Func<T>)Function to execute and return the value on the UI thread.

Invoke

#
public virtual void Invoke(Action action)
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.
action (Action)Action to invoke

InvokeAsync

#
public Task InvokeAsync(Action action)
Invokes the specified action on the UI thread asynchronously with a Task.
action (Action)Action to execute.
The task that is used to await when the action is completed.

InvokeAsync<T>

#
public Task<T> InvokeAsync<T>(Func<T> func)
Invokes the specified function on the UI thread asynchronously and return the result in a Task.
func (Func<T>)Function to execute and return the value.
The task that returns the result of the function.

Localize

#
public string Localize(object source, string text)
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.
source (object)Source widget to localize for.
text (string)English text to localize.
The localized text.

OnInitialized

#
protected virtual void OnInitialized(EventArgs e)
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.
e (EventArgs)Event arguments.

OnIsActiveChanged

#
protected virtual void OnIsActiveChanged(EventArgs e)
Raises the IsActiveChanged event

OnLocalizeString

#
protected internal virtual void OnLocalizeString(LocalizeEventArgs e)
Triggers the LocalizeString event.

OnNotificationActivated

#
protected virtual void OnNotificationActivated(NotificationEventArgs e)
Raises the NotificationActivated event

OnStyleChanged

protected virtual void OnStyleChanged(EventArgs e)
Handles when the Widget.Style is changed.
inherited fromWidget

OnTerminating

#
protected virtual void OnTerminating(CancelEventArgs e)
Raises the Terminating event.

OnThemeChanged

#Since v2.12
protected virtual void OnThemeChanged(EventArgs e)
Raises the ThemeChanged event.

OnUnhandledException

#
protected virtual void OnUnhandledException(UnhandledExceptionEventArgs e)
Raises the unhandled exception event.

Open

#
public void Open(string url)
Open the specified file or url with its associated application.

Quit

#
public void Quit()
Quits the application

Run

#
public virtual void Run()
Runs the application and begins the main loop.

Run

#
public virtual void Run(Dialog dialog)
Runs the application with the specified dialog and begins the main loop.
Remarks: When the dialog is closed, the application will exit.
dialog (Dialog)Dialog to show for the application.

Run

#
public virtual void Run(Form mainForm)
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

public override string ToString()
Gets a string that represents the current object with its ID if specified.
inherited fromWidget
A string value indicating the type and ID (if specified) of this widget.
Object.ToString

Events

Initialized

#
public event EventHandler<EventArgs> 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

#
public event EventHandler<EventArgs> IsActiveChanged
Occurs when the IsActive property is changed, which tracks whether the application is currently active or not.

LocalizeString

#
public event EventHandler<LocalizeEventArgs> 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

#
public event EventHandler<NotificationEventArgs> 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