@ -1,4 +1,5 @@
using System ;
using System.Reactive.Subjects ;
using Avalonia.Data ;
using Avalonia.Utilities ;
@ -10,6 +11,8 @@ namespace Avalonia
/// <typeparam name="TValue">The value type of the property.</typeparam>
public abstract class AvaloniaProperty < TValue > : AvaloniaProperty
{
private readonly Subject < AvaloniaPropertyChangedEventArgs < TValue > > _ changed ;
/// <summary>
/// Initializes a new instance of the <see cref="AvaloniaProperty{TValue}"/> class.
/// </summary>
@ -24,22 +27,61 @@ namespace Avalonia
Action < IAvaloniaObject , bool > notifying = null )
: base ( name , typeof ( TValue ) , ownerType , metadata , notifying )
{
_ changed = new Subject < AvaloniaPropertyChangedEventArgs < TValue > > ( ) ;
}
/// <summary>
/// Initializes a new instance of the <see cref="AvaloniaProperty"/> class.
/// Initializes a new instance of the <see cref="AvaloniaProperty{TValue} "/> class.
/// </summary>
/// <param name="source">The property to copy.</param>
/// <param name="ownerType">The new owner type.</param>
/// <param name="metadata">Optional overridden metadata.</param>
[Obsolete("Use constructor with AvaloniaProperty<TValue> instead.", true)]
protected AvaloniaProperty (
AvaloniaProperty source ,
Type ownerType ,
AvaloniaProperty source ,
Type ownerType ,
PropertyMetadata metadata )
: this ( source as AvaloniaProperty < TValue > ? ? throw new InvalidOperationException ( ) , ownerType , metadata )
{
}
/// <summary>
/// Initializes a new instance of the <see cref="AvaloniaProperty{TValue}"/> class.
/// </summary>
/// <param name="source">The property to copy.</param>
/// <param name="ownerType">The new owner type.</param>
/// <param name="metadata">Optional overridden metadata.</param>
protected AvaloniaProperty (
AvaloniaProperty < TValue > source ,
Type ownerType ,
PropertyMetadata metadata )
: base ( source , ownerType , metadata )
{
_ changed = source . _ changed ;
}
/// <summary>
/// Gets an observable that is fired when this property changes on any
/// <see cref="AvaloniaObject"/> instance.
/// </summary>
/// <value>
/// An observable that is fired when this property changes on any
/// <see cref="AvaloniaObject"/> instance.
/// </value>
public new IObservable < AvaloniaPropertyChangedEventArgs < TValue > > Changed = > _ changed ;
/// <summary>
/// Notifies the <see cref="Changed"/> observable.
/// </summary>
/// <param name="e">The observable arguments.</param>
internal void NotifyChanged ( AvaloniaPropertyChangedEventArgs < TValue > e )
{
_ changed . OnNext ( e ) ;
}
protected override IObservable < AvaloniaPropertyChangedEventArgs > GetChanged ( ) = > Changed ;
protected BindingValue < object > TryConvert ( object value )
{
if ( value = = UnsetValue )