StyledElement Class
Definition
Extends an Avalonia.Animation.Animatable with the following features:
- An inherited Avalonia.StyledElement.DataContext.
- Implements Avalonia.LogicalTree.ILogical to form part of a logical tree.
- A collection of class strings for custom styling.
public class StyledElement
Constructors
| Name | Description |
|---|---|
| StyledElement | Initializes a new instance of the Avalonia.StyledElement class. |
StyledElement Constructor
Initializes a new instance of the Avalonia.StyledElement class.
public StyledElement()
Methods
| Name | Description |
|---|---|
| ApplyStyling | Applies styling to the control if the control is initialized and styling is not already applied. |
| BeginInit | No summary available. |
| EndInit | No summary available. |
| 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. |
ApplyStyling Method
Applies styling to the control if the control is initialized and styling is not already applied.
public bool ApplyStyling()
Returns
bool
A value indicating whether styling is now applied to the control.
Remarks
The styling system will automatically apply styling when required, so it should not usually be necessary to call this method manually.
BeginInit Method
public void BeginInit()
EndInit Method
public void EndInit()
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. |
| Classes | Gets or sets the styled element's classes. |
| DataContext | Gets or sets the control's data context. |
| IsInitialized | Gets a value that indicates whether the element has finished initialization. |
| Name | Gets or sets the name of the styled element. |
| Parent | Gets the styled element's logical parent. |
| Resources | Gets or sets the styled element's resource dictionary. |
| StyleKey | Gets the type by which the element is styled. |
| Styles | Gets the styles for the styled element. |
| TemplatedParent | Gets the styled element whose lookless template this styled element is part of. |
| Theme | Gets or sets the theme to be applied to the element. |
| Transitions | Gets or sets the property transitions for the control. Inherited from Animatable. |
| 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.
Classes Property
Gets or sets the styled element's classes.
public Avalonia.Controls.Classes Classes { get; set; }
Remarks
Classes can be used to apply user-defined styling to styled elements, or to allow styled elements that share a common purpose to be easily selected.
DataContext Property
Gets or sets the control's data context.
public object DataContext { get; set; }
Remarks
The data context is an inherited property that specifies the default object that will be used for data binding.
IsInitialized Property
Gets a value that indicates whether the element has finished initialization.
public bool IsInitialized { get; set; }
Remarks
For more information about when IsInitialized is set, see the Avalonia.StyledElement.Initialized event.
Name Property
Gets or sets the name of the styled element.
public string Name { get; set; }
Remarks
An element's name is used to uniquely identify an element within the element's name scope. Once the element is added to a logical tree, its name cannot be changed.
Parent Property
Gets the styled element's logical parent.
public Avalonia.StyledElement Parent { get; set; }
Resources Property
Gets or sets the styled element's resource dictionary.
public Avalonia.Controls.IResourceDictionary Resources { get; set; }
StyleKey Property
Gets the type by which the element is styled.
public Type StyleKey { get; set; }
Remarks
Usually controls are styled by their own type, but there are instances where you want an element to be styled by its base type, e.g. creating SpecialButton that derives from Button and adds extra functionality but is still styled as a regular Button. To change the style for a control class, override the Avalonia.StyledElement.StyleKeyOverride property
Styles Property
Gets the styles for the styled element.
public Avalonia.Styling.Styles Styles { get; set; }
Remarks
Styles for the entire application are added to the Application.Styles collection, but each styled element may in addition define its own styles which are applied to the styled element itself and its children.
TemplatedParent Property
Gets the styled element whose lookless template this styled element is part of.
public Avalonia.AvaloniaObject TemplatedParent { get; set; }
Theme Property
Gets or sets the theme to be applied to the element.
public Avalonia.Styling.ControlTheme Theme { get; set; }
Fields
| Name | Description |
|---|---|
| DataContextProperty | Defines the Avalonia.StyledElement.DataContext property. |
| NameProperty | Defines the Avalonia.StyledElement.Name property. |
| ParentProperty | Defines the Avalonia.StyledElement.Parent property. |
| TemplatedParentProperty | Defines the Avalonia.StyledElement.TemplatedParent property. |
| ThemeProperty | Defines the Avalonia.StyledElement.Theme property. |
| TransitionsProperty | Defines the Avalonia.Animation.Animatable.Transitions property. Inherited from Animatable. |
DataContextProperty Field
Defines the Avalonia.StyledElement.DataContext property.
public Avalonia.StyledProperty<TValue><object> DataContextProperty
NameProperty Field
Defines the Avalonia.StyledElement.Name property.
public Avalonia.DirectProperty<TOwner,TValue><Avalonia.StyledElement, string> NameProperty
ParentProperty Field
Defines the Avalonia.StyledElement.Parent property.
public Avalonia.DirectProperty<TOwner,TValue><Avalonia.StyledElement, Avalonia.StyledElement> ParentProperty
TemplatedParentProperty Field
Defines the Avalonia.StyledElement.TemplatedParent property.
public Avalonia.DirectProperty<TOwner,TValue><Avalonia.StyledElement, Avalonia.AvaloniaObject> TemplatedParentProperty
ThemeProperty Field
Defines the Avalonia.StyledElement.Theme property.
public Avalonia.StyledProperty<TValue><Avalonia.Styling.ControlTheme> ThemeProperty
Events
| Name | Description |
|---|---|
| ActualThemeVariantChanged | Raised when the theme variant is changed on the element or an ancestor of the element. |
| AttachedToLogicalTree | Raised when the styled element is attached to a rooted logical tree. |
| DataContextChanged | Occurs when the Avalonia.StyledElement.DataContext property changes. |
| DetachedFromLogicalTree | Raised when the styled element is detached from a rooted logical tree. |
| Initialized | Occurs when the styled element has finished initialization. |
| ResourcesChanged | Occurs when a resource in this styled element or a parent styled element has changed. |
| 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
AttachedToLogicalTree Event
Raised when the styled element is attached to a rooted logical tree.
public event EventHandler<Avalonia.LogicalTree.LogicalTreeAttachmentEventArgs> AttachedToLogicalTree
DataContextChanged Event
Occurs when the Avalonia.StyledElement.DataContext property changes.
public event EventHandler DataContextChanged
Remarks
This event will be raised when the Avalonia.StyledElement.DataContext property has changed and all subscribers to that change have been notified.
DetachedFromLogicalTree Event
Raised when the styled element is detached from a rooted logical tree.
public event EventHandler<Avalonia.LogicalTree.LogicalTreeAttachmentEventArgs> DetachedFromLogicalTree
Initialized Event
Occurs when the styled element has finished initialization.
public event EventHandler Initialized
Remarks
The Initialized event indicates that all property values on the styled element have been set. When loading the styled element from markup, it occurs when System.ComponentModel.ISupportInitialize.EndInit is called and the styled element is attached to a rooted logical tree. When the styled element is created by code and System.ComponentModel.ISupportInitialize is not used, it is called when the styled element is attached to the visual tree.
ResourcesChanged Event
Occurs when a resource in this styled element or a parent styled element has changed.
public event EventHandler<Avalonia.Controls.ResourcesChangedEventArgs> ResourcesChanged