Table of Contents

Class AvaloniaObject

Namespace
Avalonia
Assembly
Avalonia.Base.dll

An object with AvaloniaProperty support.

public class AvaloniaObject : INotifyPropertyChanged
Inheritance
AvaloniaObject
Implements
Derived
Inherited Members
Extension Methods

Remarks

This class is analogous to DependencyObject in WPF.

Constructors

AvaloniaObject()

Initializes a new instance of the AvaloniaObject class.

public AvaloniaObject()

Properties

InheritanceParent

Gets or sets the parent object that inherited AvaloniaProperty values are inherited from.

protected AvaloniaObject? InheritanceParent { get; set; }

Property Value

AvaloniaObject

The inheritance parent.

this[AvaloniaProperty]

Gets or sets the value of a AvaloniaProperty.

public object? this[AvaloniaProperty property] { get; set; }

Parameters

property AvaloniaProperty

The property.

Property Value

object

this[IndexerDescriptor]

Gets or sets a binding for a AvaloniaProperty.

public IBinding this[IndexerDescriptor binding] { get; set; }

Parameters

binding IndexerDescriptor

The binding information.

Property Value

IBinding

Methods

Bind(AvaloniaProperty, IBinding)

Binds a AvaloniaProperty to an IBinding.

public BindingExpressionBase Bind(AvaloniaProperty property, IBinding binding)

Parameters

property AvaloniaProperty

The property.

binding IBinding

The binding.

Returns

BindingExpressionBase

The binding expression which represents the binding instance on this object.

Bind(AvaloniaProperty, IObservable<object?>, BindingPriority)

Binds a AvaloniaProperty to an observable.

public IDisposable Bind(AvaloniaProperty property, IObservable<object?> source, BindingPriority priority = BindingPriority.LocalValue)

Parameters

property AvaloniaProperty

The property.

source IObservable<object>

The observable.

priority BindingPriority

The priority of the binding.

Returns

IDisposable

A disposable which can be used to terminate the binding.

Bind<T>(DirectPropertyBase<T>, IObservable<BindingValue<T>>)

Binds a AvaloniaProperty to an observable.

public IDisposable Bind<T>(DirectPropertyBase<T> property, IObservable<BindingValue<T>> source)

Parameters

property DirectPropertyBase<T>

The property.

source IObservable<BindingValue<T>>

The observable.

Returns

IDisposable

A disposable which can be used to terminate the binding.

Type Parameters

T

The type of the property.

Bind<T>(DirectPropertyBase<T>, IObservable<object?>)

Binds a AvaloniaProperty to an observable.

public IDisposable Bind<T>(DirectPropertyBase<T> property, IObservable<object?> source)

Parameters

property DirectPropertyBase<T>

The property.

source IObservable<object>

The observable.

Returns

IDisposable

A disposable which can be used to terminate the binding.

Type Parameters

T

The type of the property.

Bind<T>(DirectPropertyBase<T>, IObservable<T>)

Binds a AvaloniaProperty to an observable.

public IDisposable Bind<T>(DirectPropertyBase<T> property, IObservable<T> source)

Parameters

property DirectPropertyBase<T>

The property.

source IObservable<T>

The observable.

Returns

IDisposable

A disposable which can be used to terminate the binding.

Type Parameters

T

The type of the property.

Bind<T>(StyledProperty<T>, IObservable<BindingValue<T>>, BindingPriority)

Binds a AvaloniaProperty to an observable.

public IDisposable Bind<T>(StyledProperty<T> property, IObservable<BindingValue<T>> source, BindingPriority priority = BindingPriority.LocalValue)

Parameters

property StyledProperty<T>

The property.

source IObservable<BindingValue<T>>

The observable.

priority BindingPriority

The priority of the binding.

Returns

IDisposable

A disposable which can be used to terminate the binding.

Type Parameters

T

The type of the property.

Bind<T>(StyledProperty<T>, IObservable<object?>, BindingPriority)

Binds a AvaloniaProperty to an observable.

public IDisposable Bind<T>(StyledProperty<T> property, IObservable<object?> source, BindingPriority priority = BindingPriority.LocalValue)

Parameters

property StyledProperty<T>

The property.

source IObservable<object>

The observable.

priority BindingPriority

The priority of the binding.

Returns

IDisposable

A disposable which can be used to terminate the binding.

Type Parameters

T

The type of the property.

Bind<T>(StyledProperty<T>, IObservable<T>, BindingPriority)

Binds a AvaloniaProperty to an observable.

public IDisposable Bind<T>(StyledProperty<T> property, IObservable<T> source, BindingPriority priority = BindingPriority.LocalValue)

Parameters

property StyledProperty<T>

The property.

source IObservable<T>

The observable.

priority BindingPriority

The priority of the binding.

Returns

IDisposable

A disposable which can be used to terminate the binding.

Type Parameters

T

The type of the property.

CheckAccess()

Returns a value indicating whether the current thread is the UI thread.

public bool CheckAccess()

Returns

bool

true if the current thread is the UI thread; otherwise false.

ClearValue(AvaloniaProperty)

Clears a AvaloniaProperty's local value.

public void ClearValue(AvaloniaProperty property)

Parameters

property AvaloniaProperty

The property.

ClearValue<T>(AvaloniaProperty<T>)

Clears a AvaloniaProperty's local value.

public void ClearValue<T>(AvaloniaProperty<T> property)

Parameters

property AvaloniaProperty<T>

The property.

Type Parameters

T

ClearValue<T>(DirectPropertyBase<T>)

Clears a AvaloniaProperty's local value.

public void ClearValue<T>(DirectPropertyBase<T> property)

Parameters

property DirectPropertyBase<T>

The property.

Type Parameters

T

ClearValue<T>(StyledProperty<T>)

Clears a AvaloniaProperty's local value.

public void ClearValue<T>(StyledProperty<T> property)

Parameters

property StyledProperty<T>

The property.

Type Parameters

T

CoerceValue(AvaloniaProperty)

Coerces the specified AvaloniaProperty.

public void CoerceValue(AvaloniaProperty property)

Parameters

property AvaloniaProperty

The property.

Equals(object?)

Compares two objects using reference equality.

public override sealed bool Equals(object? obj)

Parameters

obj object

The object to compare.

Returns

bool

Remarks

Overriding Equals and GetHashCode on an AvaloniaObject is disallowed for two reasons:

  • AvaloniaObjects are by their nature mutable
  • The presence of attached properties means that the semantics of equality are difficult to define

See https://github.com/AvaloniaUI/Avalonia/pull/2747 for the discussion that prompted this.

GetBaseValue<T>(StyledProperty<T>)

Gets an AvaloniaProperty base value.

public Optional<T> GetBaseValue<T>(StyledProperty<T> property)

Parameters

property StyledProperty<T>

The property.

Returns

Optional<T>

Type Parameters

T

Remarks

Gets the value of the property excluding animated values, otherwise Empty. Note that this method does not return property values that come from inherited or default values.

GetHashCode()

Gets the hash code for the object.

public override sealed int GetHashCode()

Returns

int

Remarks

Overriding Equals and GetHashCode on an AvaloniaObject is disallowed for two reasons:

  • AvaloniaObjects are by their nature mutable
  • The presence of attached properties means that the semantics of equality are difficult to define

See https://github.com/AvaloniaUI/Avalonia/pull/2747 for the discussion that prompted this.

GetValue(AvaloniaProperty)

Gets a AvaloniaProperty value.

public object? GetValue(AvaloniaProperty property)

Parameters

property AvaloniaProperty

The property.

Returns

object

The value.

GetValue<T>(DirectPropertyBase<T>)

Gets a AvaloniaProperty value.

public T GetValue<T>(DirectPropertyBase<T> property)

Parameters

property DirectPropertyBase<T>

The property.

Returns

T

The value.

Type Parameters

T

The type of the property.

GetValue<T>(StyledProperty<T>)

Gets a AvaloniaProperty value.

public T GetValue<T>(StyledProperty<T> property)

Parameters

property StyledProperty<T>

The property.

Returns

T

The value.

Type Parameters

T

The type of the property.

IsAnimating(AvaloniaProperty)

Checks whether a AvaloniaProperty is animating.

public bool IsAnimating(AvaloniaProperty property)

Parameters

property AvaloniaProperty

The property.

Returns

bool

True if the property is animating, otherwise false.

IsSet(AvaloniaProperty)

Checks whether a AvaloniaProperty is set on this object.

public bool IsSet(AvaloniaProperty property)

Parameters

property AvaloniaProperty

The property.

Returns

bool

True if the property is set, otherwise false.

Remarks

Returns true if property is a styled property which has a value assigned to it or a binding targeting it; otherwise false.

OnPropertyChanged(AvaloniaPropertyChangedEventArgs)

Called when a avalonia property changes on the object.

protected virtual void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)

Parameters

change AvaloniaPropertyChangedEventArgs

The property change details.

OnPropertyChangedCore(AvaloniaPropertyChangedEventArgs)

Called when a avalonia property changes on the object.

protected virtual void OnPropertyChangedCore(AvaloniaPropertyChangedEventArgs change)

Parameters

change AvaloniaPropertyChangedEventArgs

The property change details.

RaisePropertyChanged<T>(DirectPropertyBase<T>, T, T)

Raises the PropertyChanged event for a direct property.

protected void RaisePropertyChanged<T>(DirectPropertyBase<T> property, T oldValue, T newValue)

Parameters

property DirectPropertyBase<T>

The property that has changed.

oldValue T

The old property value.

newValue T

The new property value.

Type Parameters

T

SetAndRaise<T>(DirectPropertyBase<T>, ref T, T)

Sets the backing field for a direct avalonia property, raising the PropertyChanged event if the value has changed.

protected bool SetAndRaise<T>(DirectPropertyBase<T> property, ref T field, T value)

Parameters

property DirectPropertyBase<T>

The property.

field T

The backing field.

value T

The value.

Returns

bool

True if the value changed, otherwise false.

Type Parameters

T

The type of the property.

SetCurrentValue(AvaloniaProperty, object?)

Sets the value of a dependency property without changing its value source.

public void SetCurrentValue(AvaloniaProperty property, object? value)

Parameters

property AvaloniaProperty

The property.

value object

The value.

Remarks

This method is used by a component that programmatically sets the value of one of its own properties without disabling an application's declared use of the property. The method changes the effective value of the property, but existing data bindings and styles will continue to work.

The new value will have the property's current BindingPriority, even if that priority is Unset or Inherited.

SetCurrentValue<T>(StyledProperty<T>, T)

Sets the value of a dependency property without changing its value source.

public void SetCurrentValue<T>(StyledProperty<T> property, T value)

Parameters

property StyledProperty<T>

The property.

value T

The value.

Type Parameters

T

The type of the property.

Remarks

This method is used by a component that programmatically sets the value of one of its own properties without disabling an application's declared use of the property. The method changes the effective value of the property, but existing data bindings and styles will continue to work.

The new value will have the property's current BindingPriority, even if that priority is Unset or Inherited.

SetValue(AvaloniaProperty, object?, BindingPriority)

Sets a AvaloniaProperty value.

public IDisposable? SetValue(AvaloniaProperty property, object? value, BindingPriority priority = BindingPriority.LocalValue)

Parameters

property AvaloniaProperty

The property.

value object

The value.

priority BindingPriority

The priority of the value.

Returns

IDisposable

SetValue<T>(DirectPropertyBase<T>, T)

Sets a AvaloniaProperty value.

public void SetValue<T>(DirectPropertyBase<T> property, T value)

Parameters

property DirectPropertyBase<T>

The property.

value T

The value.

Type Parameters

T

The type of the property.

SetValue<T>(StyledProperty<T>, T, BindingPriority)

Sets a AvaloniaProperty value.

public IDisposable? SetValue<T>(StyledProperty<T> property, T value, BindingPriority priority = BindingPriority.LocalValue)

Parameters

property StyledProperty<T>

The property.

value T

The value.

priority BindingPriority

The priority of the value.

Returns

IDisposable

An IDisposable if setting the property can be undone, otherwise null.

Type Parameters

T

The type of the property.

UpdateDataValidation(AvaloniaProperty, BindingValueType, Exception?)

Called to update the validation state for properties for which data validation is enabled.

protected virtual void UpdateDataValidation(AvaloniaProperty property, BindingValueType state, Exception? error)

Parameters

property AvaloniaProperty

The property.

state BindingValueType

The current data binding state.

error Exception

The current data binding error, if any.

VerifyAccess()

Checks that the current thread is the UI thread and throws if not.

public void VerifyAccess()

Events

PropertyChanged

Raised when a AvaloniaProperty value changes on this object.

public event EventHandler<AvaloniaPropertyChangedEventArgs>? PropertyChanged

Event Type

EventHandler<AvaloniaPropertyChangedEventArgs>