Application Class
Definition
Encapsulates a Avalonia application.
public class Application
Remarks
The Avalonia.Application class encapsulates Avalonia application-specific functionality, including:
- A global set of Avalonia.Application.DataTemplates.
- A global set of Avalonia.Application.Styles.
- A Avalonia.Input.FocusManager.
- An Avalonia.Application.InputManager.
- Registers services needed by the rest of Avalonia in the Avalonia.Application.RegisterServices method.
- Tracks the lifetime of the application.
Constructors
| Name | Description |
|---|---|
| Application | Creates an instance of the Avalonia.Application class. |
Application Constructor
Creates an instance of the Avalonia.Application class.
public Application()
Methods
| Name | Description |
|---|---|
| Initialize | Initializes the application by loading XAML etc. |
| OnFrameworkInitializationCompleted | No summary available. |
| RegisterServices | Register's the services needed by Avalonia. |
| TryGetFeature | Queries for an optional feature. |
| TryGetResource | No summary available. |
| Bind (8 overloads) | Binds a Avalonia.AvaloniaProperty to an Avalonia.Data.BindingBase. Inherited from AvaloniaObject. |
| CheckAccess | Returns 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. |
| CoerceValue | Coerces the specified Avalonia.AvaloniaProperty. Inherited from AvaloniaObject. |
| Equals | Compares two objects using reference equality. Inherited from AvaloniaObject. |
| GetBaseValue | Inherited from AvaloniaObject. |
| GetHashCode | Gets the hash code for the object. Inherited from AvaloniaObject. |
| GetValue (3 overloads) | Gets a Avalonia.AvaloniaProperty value. Inherited from AvaloniaObject. |
| IsAnimating | Checks whether a Avalonia.AvaloniaProperty is animating. Inherited from AvaloniaObject. |
| IsSet | Checks 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. |
| VerifyAccess | Checks 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):
- IPlatformSettings
- IActivatableApplicationLifetime
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
| Name | Description |
|---|---|
| ActualThemeVariant | Gets the UI theme that is currently used by the element, which might be different than the RequestedThemeVariantProperty. |
| ApplicationLifetime | Application 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 |
| Current | Gets the current instance of the Avalonia.Application class. |
| DataContext | Gets or sets the Applications's data context. |
| DataTemplates | Gets or sets the application's global data templates. |
| Name | Application name to be used for various platform-specific purposes |
| PlatformSettings | Represents a contract for accessing global platform-specific settings. |
| RequestedThemeVariant | 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. |
| Resources | Gets the application's global resource dictionary. |
| Styles | Gets the application's global styles. |
| Dispatcher | Returns the Avalonia.AvaloniaObject.Dispatcher that this Avalonia.AvaloniaObject is associated with. Inherited from AvaloniaObject. |
| Item | Inherited 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:
- Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime
- Avalonia.Controls.ApplicationLifetimes.ISingleViewApplicationLifetime
- Avalonia.Controls.ApplicationLifetimes.ISingleTopLevelApplicationLifetime
- Avalonia.Controls.ApplicationLifetimes.IControlledApplicationLifetime
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
| Name | Description |
|---|---|
| ActualThemeVariantProperty | No summary available. |
| DataContextProperty | Defines the Avalonia.Application.DataContext property. |
| NameProperty | Defines Name property |
| RequestedThemeVariantProperty | No 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
| Name | Description |
|---|---|
| ActualThemeVariantChanged | Raised when the theme variant is changed on the element or an ancestor of the element. |
| ResourcesChanged | Raised when the resources change on the element or an ancestor of the element. |
| PropertyChanged | Raised 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