Class AvaloniaObjectExtensions
- Namespace
- Avalonia
- Assembly
- Avalonia.Base.dll
Provides extension methods for AvaloniaObject and related classes.
public static class AvaloniaObjectExtensions
- Inheritance
-
AvaloniaObjectExtensions
- Inherited Members
Methods
AddClassHandler<TTarget>(IObservable<AvaloniaPropertyChangedEventArgs>, Action<TTarget, AvaloniaPropertyChangedEventArgs>)
Subscribes to a property changed notifications for changes that originate from a
TTarget
.
public static IDisposable AddClassHandler<TTarget>(this IObservable<AvaloniaPropertyChangedEventArgs> observable, Action<TTarget, AvaloniaPropertyChangedEventArgs> action) where TTarget : AvaloniaObject
Parameters
observable
IObservable<AvaloniaPropertyChangedEventArgs>The property changed observable.
action
Action<TTarget, AvaloniaPropertyChangedEventArgs>The method to call. The parameters are the sender and the event args.
Returns
- IDisposable
A disposable that can be used to terminate the subscription.
Type Parameters
TTarget
The type of the property change sender.
AddClassHandler<TTarget, TValue>(IObservable<AvaloniaPropertyChangedEventArgs<TValue>>, Action<TTarget, AvaloniaPropertyChangedEventArgs<TValue>>)
Subscribes to a property changed notifications for changes that originate from a
TTarget
.
public static IDisposable AddClassHandler<TTarget, TValue>(this IObservable<AvaloniaPropertyChangedEventArgs<TValue>> observable, Action<TTarget, AvaloniaPropertyChangedEventArgs<TValue>> action) where TTarget : AvaloniaObject
Parameters
observable
IObservable<AvaloniaPropertyChangedEventArgs<TValue>>The property changed observable.
action
Action<TTarget, AvaloniaPropertyChangedEventArgs<TValue>>The method to call. The parameters are the sender and the event args.
Returns
- IDisposable
A disposable that can be used to terminate the subscription.
Type Parameters
TTarget
The type of the property change sender.
TValue
The type of the property.
Bind(AvaloniaObject, AvaloniaProperty, IBinding, object?)
Binds a property on an AvaloniaObject to an IBinding.
[Obsolete("Use AvaloniaObject.Bind(AvaloniaProperty, IBinding")]
public static IDisposable Bind(this AvaloniaObject target, AvaloniaProperty property, IBinding binding, object? anchor = null)
Parameters
target
AvaloniaObjectThe object.
property
AvaloniaPropertyThe property to bind.
binding
IBindingThe binding.
anchor
objectAn optional anchor from which to locate required context. When binding to objects that are not in the logical tree, certain types of binding need an anchor into the tree in order to locate named controls or resources. The
anchor
parameter can be used to provide this context.
Returns
- IDisposable
An IDisposable which can be used to cancel the binding.
Bind<T>(AvaloniaObject, AvaloniaProperty<T>, IObservable<BindingValue<T>>, BindingPriority)
Binds an AvaloniaProperty to an observable.
public static IDisposable Bind<T>(this AvaloniaObject target, AvaloniaProperty<T> property, IObservable<BindingValue<T>> source, BindingPriority priority = BindingPriority.LocalValue)
Parameters
target
AvaloniaObjectThe object.
property
AvaloniaProperty<T>The property.
source
IObservable<BindingValue<T>>The observable.
priority
BindingPriorityThe 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>(AvaloniaObject, AvaloniaProperty<T>, IObservable<T>, BindingPriority)
Binds an AvaloniaProperty to an observable.
public static IDisposable Bind<T>(this AvaloniaObject target, AvaloniaProperty<T> property, IObservable<T> source, BindingPriority priority = BindingPriority.LocalValue)
Parameters
target
AvaloniaObjectThe object.
property
AvaloniaProperty<T>The property.
source
IObservable<T>The observable.
priority
BindingPriorityThe priority of the binding.
Returns
- IDisposable
A disposable which can be used to terminate the binding.
Type Parameters
T
GetBaseValue(AvaloniaObject, AvaloniaProperty)
Gets an AvaloniaProperty base value.
public static object? GetBaseValue(this AvaloniaObject target, AvaloniaProperty property)
Parameters
target
AvaloniaObjectThe object.
property
AvaloniaPropertyThe property.
Returns
Remarks
For styled properties, gets the value of the property excluding animated values, otherwise UnsetValue. Note that this method does not return property values that come from inherited or default values.
For direct properties returns the current value of the property.
GetBaseValue<T>(AvaloniaObject, AvaloniaProperty<T>)
Gets an AvaloniaProperty base value.
public static Optional<T> GetBaseValue<T>(this AvaloniaObject target, AvaloniaProperty<T> property)
Parameters
target
AvaloniaObjectThe object.
property
AvaloniaProperty<T>The property.
Returns
- Optional<T>
Type Parameters
T
Remarks
For styled properties, 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.
For direct properties returns the current value of the property.
GetBindingObservable(AvaloniaObject, AvaloniaProperty)
Gets an observable for an AvaloniaProperty.
public static IObservable<BindingValue<object?>> GetBindingObservable(this AvaloniaObject o, AvaloniaProperty property)
Parameters
o
AvaloniaObjectThe object.
property
AvaloniaPropertyThe property.
Returns
- IObservable<BindingValue<object>>
An observable which fires immediately with the current value of the property on the object and subsequently each time the property value changes.
Remarks
The subscription to o
is created using a weak reference.
GetBindingObservable<TResult>(AvaloniaObject, AvaloniaProperty, Func<object?, TResult>)
Gets an observable for an AvaloniaProperty.
public static IObservable<BindingValue<TResult>> GetBindingObservable<TResult>(this AvaloniaObject o, AvaloniaProperty property, Func<object?, TResult> converter)
Parameters
o
AvaloniaObjectThe object.
property
AvaloniaPropertyThe property.
converter
Func<object, TResult>A method which is executed to convert each property value to
TResult
.
Returns
- IObservable<BindingValue<TResult>>
An observable which fires immediately with the current value of the property on the object and subsequently each time the property value changes.
Type Parameters
TResult
The type of the value returned by the
converter
.
Remarks
The subscription to o
is created using a weak reference.
GetBindingObservable<T>(AvaloniaObject, AvaloniaProperty<T>)
Gets an observable for an AvaloniaProperty.
public static IObservable<BindingValue<T>> GetBindingObservable<T>(this AvaloniaObject o, AvaloniaProperty<T> property)
Parameters
o
AvaloniaObjectThe object.
property
AvaloniaProperty<T>The property.
Returns
- IObservable<BindingValue<T>>
An observable which fires immediately with the current value of the property on the object and subsequently each time the property value changes.
Type Parameters
T
The property type.
Remarks
The subscription to o
is created using a weak reference.
GetBindingObservable<TSource, TResult>(AvaloniaObject, AvaloniaProperty<TSource>, Func<TSource, TResult>)
Gets an observable for an AvaloniaProperty.
public static IObservable<BindingValue<TResult>> GetBindingObservable<TSource, TResult>(this AvaloniaObject o, AvaloniaProperty<TSource> property, Func<TSource, TResult> converter)
Parameters
o
AvaloniaObjectThe object.
property
AvaloniaProperty<TSource>The property.
converter
Func<TSource, TResult>A method which is executed to convert each property value to
TResult
.
Returns
- IObservable<BindingValue<TResult>>
An observable which fires immediately with the current value of the property on the object and subsequently each time the property value changes.
Type Parameters
TSource
TResult
Remarks
The subscription to o
is created using a weak reference.
GetObservable(AvaloniaObject, AvaloniaProperty)
Gets an observable for an AvaloniaProperty.
public static IObservable<object?> GetObservable(this AvaloniaObject o, AvaloniaProperty property)
Parameters
o
AvaloniaObjectThe object.
property
AvaloniaPropertyThe property.
Returns
- IObservable<object>
An observable which fires immediately with the current value of the property on the object and subsequently each time the property value changes.
Remarks
The subscription to o
is created using a weak reference.
GetObservable<TResult>(AvaloniaObject, AvaloniaProperty, Func<object?, TResult>)
Gets an observable for an AvaloniaProperty.
public static IObservable<TResult> GetObservable<TResult>(this AvaloniaObject o, AvaloniaProperty property, Func<object?, TResult> converter)
Parameters
o
AvaloniaObjectThe object.
property
AvaloniaPropertyThe property.
converter
Func<object, TResult>A method which is executed to convert each property value to
TResult
.
Returns
- IObservable<TResult>
An observable which fires immediately with the current value of the property on the object and subsequently each time the property value changes.
Type Parameters
TResult
The type of the value returned by the
converter
.
Remarks
The subscription to o
is created using a weak reference.
GetObservable<T>(AvaloniaObject, AvaloniaProperty<T>)
Gets an observable for an AvaloniaProperty.
public static IObservable<T> GetObservable<T>(this AvaloniaObject o, AvaloniaProperty<T> property)
Parameters
o
AvaloniaObjectThe object.
property
AvaloniaProperty<T>The property.
Returns
- IObservable<T>
An observable which fires immediately with the current value of the property on the object and subsequently each time the property value changes.
Type Parameters
T
The property type.
Remarks
The subscription to o
is created using a weak reference.
GetObservable<TSource, TResult>(AvaloniaObject, AvaloniaProperty<TSource>, Func<TSource, TResult>)
Gets an observable for an AvaloniaProperty.
public static IObservable<TResult> GetObservable<TSource, TResult>(this AvaloniaObject o, AvaloniaProperty<TSource> property, Func<TSource, TResult> converter)
Parameters
o
AvaloniaObjectThe object.
property
AvaloniaProperty<TSource>The property.
converter
Func<TSource, TResult>A method which is executed to convert each property value to
TResult
.
Returns
- IObservable<TResult>
An observable which fires immediately with the current value of the property on the object and subsequently each time the property value changes.
Type Parameters
TSource
The type of the values held by the
property
.TResult
The type of the value returned by the
converter
.
Remarks
The subscription to o
is created using a weak reference.
GetPropertyChangedObservable(AvaloniaObject, AvaloniaProperty)
Gets an observable that listens for property changed events for an AvaloniaProperty.
public static IObservable<AvaloniaPropertyChangedEventArgs> GetPropertyChangedObservable(this AvaloniaObject o, AvaloniaProperty property)
Parameters
o
AvaloniaObjectThe object.
property
AvaloniaPropertyThe property.
Returns
- IObservable<AvaloniaPropertyChangedEventArgs>
An observable which when subscribed pushes the property changed event args each time a PropertyChanged event is raised for the specified property.
GetValue<T>(AvaloniaObject, AvaloniaProperty<T>)
Gets a AvaloniaProperty value.
public static T GetValue<T>(this AvaloniaObject target, AvaloniaProperty<T> property)
Parameters
target
AvaloniaObjectThe object.
property
AvaloniaProperty<T>The property.
Returns
- T
The value.
Type Parameters
T
The type of the property.
ToBinding<T>(IObservable<T>)
Converts an IObservable<T> to an IBinding.
public static IBinding ToBinding<T>(this IObservable<T> source)
Parameters
source
IObservable<T>The observable
Returns
Type Parameters
T
The type produced by the observable.