|
|
@ -25,7 +25,7 @@ namespace Avalonia |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets an observable for a <see cref="AvaloniaProperty"/>.
|
|
|
/// Gets an observable for an <see cref="AvaloniaProperty"/>.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="o">The object.</param>
|
|
|
/// <param name="o">The object.</param>
|
|
|
/// <param name="property">The property.</param>
|
|
|
/// <param name="property">The property.</param>
|
|
|
@ -44,7 +44,7 @@ namespace Avalonia |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets an observable for a <see cref="AvaloniaProperty"/>.
|
|
|
/// Gets an observable for an <see cref="AvaloniaProperty"/>.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="o">The object.</param>
|
|
|
/// <param name="o">The object.</param>
|
|
|
/// <typeparam name="T">The property type.</typeparam>
|
|
|
/// <typeparam name="T">The property type.</typeparam>
|
|
|
@ -64,7 +64,7 @@ namespace Avalonia |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets an observable for a <see cref="AvaloniaProperty"/>.
|
|
|
/// Gets an observable for an <see cref="AvaloniaProperty"/>.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="o">The object.</param>
|
|
|
/// <param name="o">The object.</param>
|
|
|
/// <param name="property">The property.</param>
|
|
|
/// <param name="property">The property.</param>
|
|
|
@ -85,7 +85,7 @@ namespace Avalonia |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets an observable for a <see cref="AvaloniaProperty"/>.
|
|
|
/// Gets an observable for an <see cref="AvaloniaProperty"/>.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="o">The object.</param>
|
|
|
/// <param name="o">The object.</param>
|
|
|
/// <typeparam name="T">The property type.</typeparam>
|
|
|
/// <typeparam name="T">The property type.</typeparam>
|
|
|
@ -128,7 +128,7 @@ namespace Avalonia |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets a subject for a <see cref="AvaloniaProperty"/>.
|
|
|
/// Gets a subject for an <see cref="AvaloniaProperty"/>.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="o">The object.</param>
|
|
|
/// <param name="o">The object.</param>
|
|
|
/// <param name="property">The property.</param>
|
|
|
/// <param name="property">The property.</param>
|
|
|
@ -150,7 +150,7 @@ namespace Avalonia |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets a subject for a <see cref="AvaloniaProperty"/>.
|
|
|
/// Gets a subject for an <see cref="AvaloniaProperty"/>.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <typeparam name="T">The property type.</typeparam>
|
|
|
/// <typeparam name="T">The property type.</typeparam>
|
|
|
/// <param name="o">The object.</param>
|
|
|
/// <param name="o">The object.</param>
|
|
|
@ -230,30 +230,7 @@ namespace Avalonia |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Binds a <see cref="AvaloniaProperty"/> to an observable.
|
|
|
/// Binds an <see cref="AvaloniaProperty"/> to an observable.
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="target">The object.</param>
|
|
|
|
|
|
/// <param name="property">The property.</param>
|
|
|
|
|
|
/// <param name="source">The observable.</param>
|
|
|
|
|
|
/// <param name="priority">The priority of the binding.</param>
|
|
|
|
|
|
/// <returns>
|
|
|
|
|
|
/// A disposable which can be used to terminate the binding.
|
|
|
|
|
|
/// </returns>
|
|
|
|
|
|
public static IDisposable Bind( |
|
|
|
|
|
this IAvaloniaObject target, |
|
|
|
|
|
AvaloniaProperty property, |
|
|
|
|
|
IObservable<BindingValue<object?>> source, |
|
|
|
|
|
BindingPriority priority = BindingPriority.LocalValue) |
|
|
|
|
|
{ |
|
|
|
|
|
target = target ?? throw new ArgumentNullException(nameof(target)); |
|
|
|
|
|
property = property ?? throw new ArgumentNullException(nameof(property)); |
|
|
|
|
|
source = source ?? throw new ArgumentNullException(nameof(source)); |
|
|
|
|
|
|
|
|
|
|
|
return property.RouteBind(target, source, priority); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Binds a <see cref="AvaloniaProperty"/> to an observable.
|
|
|
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <typeparam name="T">The type of the property.</typeparam>
|
|
|
/// <typeparam name="T">The type of the property.</typeparam>
|
|
|
/// <param name="target">The object.</param>
|
|
|
/// <param name="target">The object.</param>
|
|
|
@ -273,42 +250,22 @@ namespace Avalonia |
|
|
property = property ?? throw new ArgumentNullException(nameof(property)); |
|
|
property = property ?? throw new ArgumentNullException(nameof(property)); |
|
|
source = source ?? throw new ArgumentNullException(nameof(source)); |
|
|
source = source ?? throw new ArgumentNullException(nameof(source)); |
|
|
|
|
|
|
|
|
return property switch |
|
|
if (target is AvaloniaObject ao) |
|
|
{ |
|
|
{ |
|
|
StyledPropertyBase<T> styled => target.Bind(styled, source, priority), |
|
|
return property switch |
|
|
DirectPropertyBase<T> direct => target.Bind(direct, source), |
|
|
{ |
|
|
_ => throw new NotSupportedException("Unsupported AvaloniaProperty type."), |
|
|
StyledPropertyBase<T> styled => ao.Bind(styled, source, priority), |
|
|
}; |
|
|
DirectPropertyBase<T> direct => ao.Bind(direct, source), |
|
|
} |
|
|
_ => throw new NotSupportedException("Unsupported AvaloniaProperty type."), |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
throw new NotSupportedException("Custom implementations of IAvaloniaObject not supported."); |
|
|
/// Binds a <see cref="AvaloniaProperty"/> to an observable.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="target">The object.</param>
|
|
|
|
|
|
/// <param name="property">The property.</param>
|
|
|
|
|
|
/// <param name="source">The observable.</param>
|
|
|
|
|
|
/// <param name="priority">The priority of the binding.</param>
|
|
|
|
|
|
/// <returns>
|
|
|
|
|
|
/// A disposable which can be used to terminate the binding.
|
|
|
|
|
|
/// </returns>
|
|
|
|
|
|
public static IDisposable Bind( |
|
|
|
|
|
this IAvaloniaObject target, |
|
|
|
|
|
AvaloniaProperty property, |
|
|
|
|
|
IObservable<object?> source, |
|
|
|
|
|
BindingPriority priority = BindingPriority.LocalValue) |
|
|
|
|
|
{ |
|
|
|
|
|
target = target ?? throw new ArgumentNullException(nameof(target)); |
|
|
|
|
|
property = property ?? throw new ArgumentNullException(nameof(property)); |
|
|
|
|
|
source = source ?? throw new ArgumentNullException(nameof(source)); |
|
|
|
|
|
|
|
|
|
|
|
return target.Bind( |
|
|
|
|
|
property, |
|
|
|
|
|
source.ToBindingValue(), |
|
|
|
|
|
priority); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Binds a <see cref="AvaloniaProperty"/> to an observable.
|
|
|
/// Binds an <see cref="AvaloniaProperty"/> to an observable.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="target">The object.</param>
|
|
|
/// <param name="target">The object.</param>
|
|
|
/// <param name="property">The property.</param>
|
|
|
/// <param name="property">The property.</param>
|
|
|
@ -334,7 +291,7 @@ namespace Avalonia |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Binds a property on an <see cref="IAvaloniaObject"/> to an <see cref="IBinding"/>.
|
|
|
/// Binds a property on an <see cref="AvaloniaObject"/> to an <see cref="IBinding"/>.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="target">The object.</param>
|
|
|
/// <param name="target">The object.</param>
|
|
|
/// <param name="property">The property to bind.</param>
|
|
|
/// <param name="property">The property to bind.</param>
|
|
|
@ -374,56 +331,6 @@ namespace Avalonia |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Clears a <see cref="AvaloniaProperty"/>'s local value.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="target">The object.</param>
|
|
|
|
|
|
/// <param name="property">The property.</param>
|
|
|
|
|
|
public static void ClearValue(this IAvaloniaObject target, AvaloniaProperty property) |
|
|
|
|
|
{ |
|
|
|
|
|
target = target ?? throw new ArgumentNullException(nameof(target)); |
|
|
|
|
|
property = property ?? throw new ArgumentNullException(nameof(property)); |
|
|
|
|
|
|
|
|
|
|
|
property.RouteClearValue(target); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Clears a <see cref="AvaloniaProperty"/>'s local value.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="target">The object.</param>
|
|
|
|
|
|
/// <param name="property">The property.</param>
|
|
|
|
|
|
public static void ClearValue<T>(this IAvaloniaObject target, AvaloniaProperty<T> property) |
|
|
|
|
|
{ |
|
|
|
|
|
target = target ?? throw new ArgumentNullException(nameof(target)); |
|
|
|
|
|
property = property ?? throw new ArgumentNullException(nameof(property)); |
|
|
|
|
|
|
|
|
|
|
|
switch (property) |
|
|
|
|
|
{ |
|
|
|
|
|
case StyledPropertyBase<T> styled: |
|
|
|
|
|
target.ClearValue(styled); |
|
|
|
|
|
break; |
|
|
|
|
|
case DirectPropertyBase<T> direct: |
|
|
|
|
|
target.ClearValue(direct); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
throw new NotSupportedException("Unsupported AvaloniaProperty type."); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets a <see cref="AvaloniaProperty"/> value.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="target">The object.</param>
|
|
|
|
|
|
/// <param name="property">The property.</param>
|
|
|
|
|
|
/// <returns>The value.</returns>
|
|
|
|
|
|
public static object? GetValue(this IAvaloniaObject target, AvaloniaProperty property) |
|
|
|
|
|
{ |
|
|
|
|
|
target = target ?? throw new ArgumentNullException(nameof(target)); |
|
|
|
|
|
property = property ?? throw new ArgumentNullException(nameof(property)); |
|
|
|
|
|
|
|
|
|
|
|
return property.RouteGetValue(target); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Gets a <see cref="AvaloniaProperty"/> value.
|
|
|
/// Gets a <see cref="AvaloniaProperty"/> value.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
@ -436,12 +343,18 @@ namespace Avalonia |
|
|
target = target ?? throw new ArgumentNullException(nameof(target)); |
|
|
target = target ?? throw new ArgumentNullException(nameof(target)); |
|
|
property = property ?? throw new ArgumentNullException(nameof(property)); |
|
|
property = property ?? throw new ArgumentNullException(nameof(property)); |
|
|
|
|
|
|
|
|
return property switch |
|
|
if (target is AvaloniaObject ao) |
|
|
{ |
|
|
{ |
|
|
StyledPropertyBase<T> styled => target.GetValue(styled), |
|
|
return property switch |
|
|
DirectPropertyBase<T> direct => target.GetValue(direct), |
|
|
{ |
|
|
_ => throw new NotSupportedException("Unsupported AvaloniaProperty type.") |
|
|
StyledPropertyBase<T> styled => ao.GetValue(styled), |
|
|
}; |
|
|
DirectPropertyBase<T> direct => ao.GetValue(direct), |
|
|
|
|
|
_ => throw new NotSupportedException("Unsupported AvaloniaProperty type.") |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
throw new NotSupportedException("Custom implementations of IAvaloniaObject not supported."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
@ -456,7 +369,7 @@ namespace Avalonia |
|
|
/// <see cref="AvaloniaProperty.UnsetValue"/>. Note that this method does not return
|
|
|
/// <see cref="AvaloniaProperty.UnsetValue"/>. Note that this method does not return
|
|
|
/// property values that come from inherited or default values.
|
|
|
/// property values that come from inherited or default values.
|
|
|
///
|
|
|
///
|
|
|
/// For direct properties returns <see cref="GetValue(IAvaloniaObject, AvaloniaProperty)"/>.
|
|
|
/// For direct properties returns the current value of the property.
|
|
|
/// </remarks>
|
|
|
/// </remarks>
|
|
|
public static object? GetBaseValue( |
|
|
public static object? GetBaseValue( |
|
|
this IAvaloniaObject target, |
|
|
this IAvaloniaObject target, |
|
|
@ -466,7 +379,9 @@ namespace Avalonia |
|
|
target = target ?? throw new ArgumentNullException(nameof(target)); |
|
|
target = target ?? throw new ArgumentNullException(nameof(target)); |
|
|
property = property ?? throw new ArgumentNullException(nameof(property)); |
|
|
property = property ?? throw new ArgumentNullException(nameof(property)); |
|
|
|
|
|
|
|
|
return property.RouteGetBaseValue(target, maxPriority); |
|
|
if (target is AvaloniaObject ao) |
|
|
|
|
|
return property.RouteGetBaseValue(ao, maxPriority); |
|
|
|
|
|
throw new NotSupportedException("Custom implementations of IAvaloniaObject not supported."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
@ -481,8 +396,7 @@ namespace Avalonia |
|
|
/// <see cref="Optional{T}.Empty"/>. Note that this method does not return property values
|
|
|
/// <see cref="Optional{T}.Empty"/>. Note that this method does not return property values
|
|
|
/// that come from inherited or default values.
|
|
|
/// that come from inherited or default values.
|
|
|
///
|
|
|
///
|
|
|
/// For direct properties returns
|
|
|
/// For direct properties returns the current value of the property.
|
|
|
/// <see cref="IAvaloniaObject.GetValue{T}(DirectPropertyBase{T})"/>.
|
|
|
|
|
|
/// </remarks>
|
|
|
/// </remarks>
|
|
|
public static Optional<T> GetBaseValue<T>( |
|
|
public static Optional<T> GetBaseValue<T>( |
|
|
this IAvaloniaObject target, |
|
|
this IAvaloniaObject target, |
|
|
@ -492,69 +406,18 @@ namespace Avalonia |
|
|
target = target ?? throw new ArgumentNullException(nameof(target)); |
|
|
target = target ?? throw new ArgumentNullException(nameof(target)); |
|
|
property = property ?? throw new ArgumentNullException(nameof(property)); |
|
|
property = property ?? throw new ArgumentNullException(nameof(property)); |
|
|
|
|
|
|
|
|
target = target ?? throw new ArgumentNullException(nameof(target)); |
|
|
if (target is AvaloniaObject ao) |
|
|
property = property ?? throw new ArgumentNullException(nameof(property)); |
|
|
|
|
|
|
|
|
|
|
|
return property switch |
|
|
|
|
|
{ |
|
|
{ |
|
|
StyledPropertyBase<T> styled => target.GetBaseValue(styled, maxPriority), |
|
|
return property switch |
|
|
DirectPropertyBase<T> direct => target.GetValue(direct), |
|
|
{ |
|
|
_ => throw new NotSupportedException("Unsupported AvaloniaProperty type.") |
|
|
StyledPropertyBase<T> styled => ao.GetBaseValue(styled, maxPriority), |
|
|
}; |
|
|
DirectPropertyBase<T> direct => ao.GetValue(direct), |
|
|
} |
|
|
_ => throw new NotSupportedException("Unsupported AvaloniaProperty type.") |
|
|
|
|
|
}; |
|
|
/// <summary>
|
|
|
|
|
|
/// Sets a <see cref="AvaloniaProperty"/> value.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="target">The object.</param>
|
|
|
|
|
|
/// <param name="property">The property.</param>
|
|
|
|
|
|
/// <param name="value">The value.</param>
|
|
|
|
|
|
/// <param name="priority">The priority of the value.</param>
|
|
|
|
|
|
/// <returns>
|
|
|
|
|
|
/// An <see cref="IDisposable"/> if setting the property can be undone, otherwise null.
|
|
|
|
|
|
/// </returns>
|
|
|
|
|
|
public static IDisposable? SetValue( |
|
|
|
|
|
this IAvaloniaObject target, |
|
|
|
|
|
AvaloniaProperty property, |
|
|
|
|
|
object? value, |
|
|
|
|
|
BindingPriority priority = BindingPriority.LocalValue) |
|
|
|
|
|
{ |
|
|
|
|
|
target = target ?? throw new ArgumentNullException(nameof(target)); |
|
|
|
|
|
property = property ?? throw new ArgumentNullException(nameof(property)); |
|
|
|
|
|
|
|
|
|
|
|
return property.RouteSetValue(target, value, priority); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sets a <see cref="AvaloniaProperty"/> value.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="T">The type of the property.</typeparam>
|
|
|
|
|
|
/// <param name="target">The object.</param>
|
|
|
|
|
|
/// <param name="property">The property.</param>
|
|
|
|
|
|
/// <param name="value">The value.</param>
|
|
|
|
|
|
/// <param name="priority">The priority of the value.</param>
|
|
|
|
|
|
/// <returns>
|
|
|
|
|
|
/// An <see cref="IDisposable"/> if setting the property can be undone, otherwise null.
|
|
|
|
|
|
/// </returns>
|
|
|
|
|
|
public static IDisposable? SetValue<T>( |
|
|
|
|
|
this IAvaloniaObject target, |
|
|
|
|
|
AvaloniaProperty<T> property, |
|
|
|
|
|
T value, |
|
|
|
|
|
BindingPriority priority = BindingPriority.LocalValue) |
|
|
|
|
|
{ |
|
|
|
|
|
target = target ?? throw new ArgumentNullException(nameof(target)); |
|
|
|
|
|
property = property ?? throw new ArgumentNullException(nameof(property)); |
|
|
|
|
|
|
|
|
|
|
|
switch (property) |
|
|
|
|
|
{ |
|
|
|
|
|
case StyledPropertyBase<T> styled: |
|
|
|
|
|
return target.SetValue(styled, value, priority); |
|
|
|
|
|
case DirectPropertyBase<T> direct: |
|
|
|
|
|
target.SetValue(direct, value); |
|
|
|
|
|
return null; |
|
|
|
|
|
default: |
|
|
|
|
|
throw new NotSupportedException("Unsupported AvaloniaProperty type."); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
throw new NotSupportedException("Custom implementations of IAvaloniaObject not supported."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
@ -622,17 +485,6 @@ namespace Avalonia |
|
|
return observable.Subscribe(e => SubscribeAdapter(e, handler)); |
|
|
return observable.Subscribe(e => SubscribeAdapter(e, handler)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets a description of a property that van be used in observables.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="o">The object.</param>
|
|
|
|
|
|
/// <param name="property">The property</param>
|
|
|
|
|
|
/// <returns>The description.</returns>
|
|
|
|
|
|
private static string GetDescription(IAvaloniaObject o, AvaloniaProperty property) |
|
|
|
|
|
{ |
|
|
|
|
|
return $"{o.GetType().Name}.{property.Name}"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Observer method for <see cref="AddClassHandler{TTarget}(IObservable{AvaloniaPropertyChangedEventArgs},
|
|
|
/// Observer method for <see cref="AddClassHandler{TTarget}(IObservable{AvaloniaPropertyChangedEventArgs},
|
|
|
/// Func{TTarget, Action{AvaloniaPropertyChangedEventArgs}})"/>.
|
|
|
/// Func{TTarget, Action{AvaloniaPropertyChangedEventArgs}})"/>.
|
|
|
|