Skip to main content

Application Class

Definition

Namespace:Avalonia
Assembly:Avalonia.Controls
Package:Avalonia

Encapsulates a Avalonia application.

public class Application

Remarks

The Avalonia.Application class encapsulates Avalonia application-specific functionality, including:

Constructors

NameDescription
ApplicationCreates an instance of the Avalonia.Application class.

Application Constructor

Creates an instance of the Avalonia.Application class.

public Application()

Methods

NameDescription
InitializeInitializes the application by loading XAML etc.
OnFrameworkInitializationCompletedNo summary available.
RegisterServicesRegister's the services needed by Avalonia.
TryGetFeatureQueries for an optional feature.
TryGetResourceNo summary available.
Bind (8 overloads)Binds a Avalonia.AvaloniaProperty to an Avalonia.Data.BindingBase. Inherited from AvaloniaObject.
CheckAccessReturns a value indicating whether the current thread is the UI thread. Inherited from AvaloniaObject.
ClearValue (4 overloads)Clears a Avalonia.AvaloniaProperty's local value. Inherited from AvaloniaObject.
CoerceValueCoerces the specified Avalonia.AvaloniaProperty. Inherited from AvaloniaObject.
EqualsCompares two objects using reference equality. Inherited from AvaloniaObject.
GetBaseValueInherited from AvaloniaObject.
GetHashCodeGets the hash code for the object. Inherited from AvaloniaObject.
GetValue (3 overloads)Gets a Avalonia.AvaloniaProperty value. Inherited from AvaloniaObject.
IsAnimatingChecks whether a Avalonia.AvaloniaProperty is animating. Inherited from AvaloniaObject.
IsSetChecks whether a Avalonia.AvaloniaProperty is set on this object. Inherited from AvaloniaObject.
SetCurrentValue (2 overloads)Sets the value of a dependency property without changing its value source. Inherited from AvaloniaObject.
SetValue (3 overloads)Sets a Avalonia.AvaloniaProperty value. Inherited from AvaloniaObject.
VerifyAccessChecks that the current thread is the UI thread and throws if not. Inherited from AvaloniaObject.

Initialize Method

Initializes the application by loading XAML etc.

public void Initialize()

OnFrameworkInitializationCompleted Method

public void OnFrameworkInitializationCompleted()

RegisterServices Method

Register's the services needed by Avalonia.

public void RegisterServices()

TryGetFeature Method

Queries for an optional feature.

public object TryGetFeature(Type featureType)

Parameters

featureType Type

Feature type.

Returns

object

Remarks

Features currently supported by Avalonia.Application.TryGetFeature(Type):

TryGetResource Method

public bool TryGetResource(object key, Avalonia.Styling.ThemeVariant theme, object& value)

Parameters

key object

theme Avalonia.Styling.ThemeVariant

value object&

Returns

bool

Properties

NameDescription
ActualThemeVariantGets the UI theme that is currently used by the element, which might be different than the RequestedThemeVariantProperty.
ApplicationLifetimeApplication lifetime, use it for things like setting the main window and exiting the app from code Currently supported lifetimes are: - Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime - Avalonia.Controls.ApplicationLifetimes.ISingleViewApplicationLifetime - Avalonia.Controls.ApplicationLifetimes.ISingleTopLevelApplicationLifetime - Avalonia.Controls.ApplicationLifetimes.IControlledApplicationLifetime
CurrentGets the current instance of the Avalonia.Application class.
DataContextGets or sets the Applications's data context.
DataTemplatesGets or sets the application's global data templates.
NameApplication name to be used for various platform-specific purposes
PlatformSettingsRepresents a contract for accessing global platform-specific settings.
RequestedThemeVariantGets or sets the UI theme variant that is used by the control (and its child elements) for resource determination. The UI theme you specify with ThemeVariant can override the app-level ThemeVariant.
ResourcesGets the application's global resource dictionary.
StylesGets the application's global styles.
DispatcherReturns the Avalonia.AvaloniaObject.Dispatcher that this Avalonia.AvaloniaObject is associated with. Inherited from AvaloniaObject.
ItemInherited from AvaloniaObject.

ActualThemeVariant Property

Gets the UI theme that is currently used by the element, which might be different than the RequestedThemeVariantProperty.

public Avalonia.Styling.ThemeVariant ActualThemeVariant { get; set; }

Returns

If current control is contained in the ThemeVariantScope, TopLevel or Application with non-default RequestedThemeVariant, that value will be returned. Otherwise, current OS theme variant is returned.

ApplicationLifetime Property

Application lifetime, use it for things like setting the main window and exiting the app from code Currently supported lifetimes are:

public Avalonia.Controls.ApplicationLifetimes.IApplicationLifetime ApplicationLifetime { get; set; }

Current Property

Gets the current instance of the Avalonia.Application class.

public Avalonia.Application Current { get; set; }

Value

The current instance of the Avalonia.Application class.

DataContext Property

Gets or sets the Applications's data context.

public object DataContext { get; set; }

Remarks

The data context property specifies the default object that will be used for data binding.

DataTemplates Property

Gets or sets the application's global data templates.

public Avalonia.Controls.Templates.DataTemplates DataTemplates { get; set; }

Value

The application's global data templates.

Name Property

Application name to be used for various platform-specific purposes

public string Name { get; set; }

PlatformSettings Property

Represents a contract for accessing global platform-specific settings.

public Avalonia.Platform.IPlatformSettings PlatformSettings { get; set; }

Remarks

PlatformSettings can be null only if application wasn't initialized yet. Avalonia.Controls.TopLevel's Avalonia.Controls.TopLevel.PlatformSettings is an equivalent API which should always be preferred over a global one, as specific top levels might have different settings set-up.

RequestedThemeVariant Property

Gets or sets the UI theme variant that is used by the control (and its child elements) for resource determination. The UI theme you specify with ThemeVariant can override the app-level ThemeVariant.

public Avalonia.Styling.ThemeVariant RequestedThemeVariant { get; set; }

Remarks

Setting RequestedThemeVariant to Avalonia.Styling.ThemeVariant.Default will apply parent's actual theme variant on the current scope.

Resources Property

Gets the application's global resource dictionary.

public Avalonia.Controls.IResourceDictionary Resources { get; set; }

Styles Property

Gets the application's global styles.

public Avalonia.Styling.Styles Styles { get; set; }

Value

The application's global styles.

Remarks

Global styles apply to all windows in the application.

Fields

NameDescription
ActualThemeVariantPropertyNo summary available.
DataContextPropertyDefines the Avalonia.Application.DataContext property.
NamePropertyDefines Name property
RequestedThemeVariantPropertyNo summary available.

ActualThemeVariantProperty Field

public Avalonia.StyledProperty<Avalonia.Styling.ThemeVariant> ActualThemeVariantProperty

DataContextProperty Field

Defines the Avalonia.Application.DataContext property.

public Avalonia.StyledProperty<object> DataContextProperty

NameProperty Field

Defines Name property

public Avalonia.DirectProperty<Avalonia.Application, string> NameProperty

RequestedThemeVariantProperty Field

public Avalonia.StyledProperty<Avalonia.Styling.ThemeVariant> RequestedThemeVariantProperty

Events

NameDescription
ActualThemeVariantChangedRaised when the theme variant is changed on the element or an ancestor of the element.
ResourcesChangedRaised when the resources change on the element or an ancestor of the element.
PropertyChangedRaised when a Avalonia.AvaloniaProperty value changes on this object. Inherited from AvaloniaObject.

ActualThemeVariantChanged Event

Raised when the theme variant is changed on the element or an ancestor of the element.

public event EventHandler ActualThemeVariantChanged

ResourcesChanged Event

Raised when the resources change on the element or an ancestor of the element.

public event EventHandler<Avalonia.Controls.ResourcesChangedEventArgs> ResourcesChanged