/// <summary> /// Registers a direct <see cref="AvaloniaProperty"/>. /// </summary> /// <typeparam name="TOwner">The type of the class that is registering the property.</typeparam> /// <typeparam name="TValue">The type of the property's value.</typeparam> /// <param name="name">The name of the property.</param> /// <param name="getter">Gets the current value of the property.</param> /// <param name="setter">Sets the value of the property.</param> /// <param name="unsetValue">The value to use when the property is cleared.</param> /// <param name="defaultBindingMode">The default binding mode for the property.</param> /// <param name="enableDataValidation"> /// Whether the property is interested in data validation. /// </param> /// <returns>A <see cref="AvaloniaProperty{TValue}"/></returns> public static DirectProperty <TOwner, TValue> RegisterDirect <TOwner, TValue>( string name, Func <TOwner, TValue> getter, Action <TOwner, TValue> setter = null, TValue unsetValue = default(TValue), BindingMode defaultBindingMode = BindingMode.OneWay, bool enableDataValidation = false) where TOwner : IAvaloniaObject { Contract.Requires <ArgumentNullException>(name != null); Contract.Requires <ArgumentNullException>(getter != null); var metadata = new DirectPropertyMetadata <TValue>( unsetValue: unsetValue, defaultBindingMode: defaultBindingMode); var result = new DirectProperty <TOwner, TValue>( name, getter, setter, metadata, enableDataValidation); AvaloniaPropertyRegistry.Instance.Register(typeof(TOwner), result); return(result); }
/// <summary> /// Registers the direct property on another type. /// </summary> /// <typeparam name="TNewOwner">The type of the additional owner.</typeparam> /// <param name="getter">Gets the current value of the property.</param> /// <param name="setter">Sets the value of the property.</param> /// <param name="unsetValue"> /// The value to use when the property is set to <see cref="AvaloniaProperty.UnsetValue"/> /// </param> /// <param name="defaultBindingMode">The default binding mode for the property.</param> /// <param name="enableDataValidation"> /// Whether the property is interested in data validation. /// </param> /// <returns>The property.</returns> public DirectProperty <TNewOwner, TValue> AddOwnerWithDataValidation <TNewOwner>( Func <TNewOwner, TValue> getter, Action <TNewOwner, TValue> setter, TValue unsetValue = default(TValue), BindingMode defaultBindingMode = BindingMode.Default, bool enableDataValidation = false) where TNewOwner : AvaloniaObject { var metadata = new DirectPropertyMetadata <TValue>( unsetValue: unsetValue, defaultBindingMode: defaultBindingMode, enableDataValidation: enableDataValidation); metadata.Merge(GetMetadata <TOwner>(), this); var result = new DirectProperty <TNewOwner, TValue>( this, getter, setter, metadata, enableDataValidation); AvaloniaPropertyRegistry.Instance.Register(typeof(TNewOwner), result); return(result); }
/// <summary> /// Initializes a new instance of the <see cref="AvaloniaProperty"/> class. /// </summary> /// <param name="source">The property to copy.</param> /// <param name="getter">Gets the current value of the property.</param> /// <param name="setter">Sets the value of the property. May be null.</param> /// <param name="metadata">Optional overridden metadata.</param> private DirectProperty( DirectPropertyBase <TValue> source, Func <TOwner, TValue> getter, Action <TOwner, TValue>?setter, DirectPropertyMetadata <TValue> metadata) : base(source, typeof(TOwner), metadata) { Getter = getter ?? throw new ArgumentNullException(nameof(getter)); Setter = setter; }
/// <summary> /// Initializes a new instance of the <see cref="DirectProperty{TOwner, TValue}"/> class. /// </summary> /// <param name="name">The name of the property.</param> /// <param name="getter">Gets the current value of the property.</param> /// <param name="setter">Sets the value of the property. May be null.</param> /// <param name="metadata">The property metadata.</param> public DirectProperty( string name, Func <TOwner, TValue> getter, Action <TOwner, TValue>?setter, DirectPropertyMetadata <TValue> metadata) : base(name, typeof(TOwner), metadata) { Getter = getter ?? throw new ArgumentNullException(nameof(getter)); Setter = setter; }
/// <summary> /// Initializes a new instance of the <see cref="AvaloniaProperty"/> class. /// </summary> /// <param name="source">The property to copy.</param> /// <param name="getter">Gets the current value of the property.</param> /// <param name="setter">Sets the value of the property. May be null.</param> /// <param name="metadata">Optional overridden metadata.</param> private DirectProperty( DirectPropertyBase <TValue> source, Func <TOwner, TValue> getter, Action <TOwner, TValue> setter, DirectPropertyMetadata <TValue> metadata) : base(source, typeof(TOwner), metadata) { Contract.Requires <ArgumentNullException>(getter != null); Getter = getter; Setter = setter; }
/// <summary> /// Initializes a new instance of the <see cref="DirectProperty{TOwner, TValue}"/> class. /// </summary> /// <param name="name">The name of the property.</param> /// <param name="getter">Gets the current value of the property.</param> /// <param name="setter">Sets the value of the property. May be null.</param> /// <param name="metadata">The property metadata.</param> public DirectProperty( string name, Func <TOwner, TValue> getter, Action <TOwner, TValue> setter, DirectPropertyMetadata <TValue> metadata) : base(name, typeof(TOwner), metadata) { Contract.Requires <ArgumentNullException>(getter != null); Getter = getter; Setter = setter; }
/// <summary> /// Overrides the metadata for the property on the specified type. /// </summary> /// <param name="type">The type.</param> /// <param name="metadata">The metadata.</param> public void OverrideMetadata(Type type, DirectPropertyMetadata <TValue> metadata) { base.OverrideMetadata(type, metadata); }
/// <summary> /// Overrides the metadata for the property on the specified type. /// </summary> /// <typeparam name="T">The type.</typeparam> /// <param name="metadata">The metadata.</param> public void OverrideMetadata <T>(DirectPropertyMetadata <TValue> metadata) where T : IAvaloniaObject { base.OverrideMetadata(typeof(T), metadata); }