using Avalonia.Data; namespace Avalonia { /// /// Base class for avalonia property metadata. /// public abstract class AvaloniaPropertyMetadata { private BindingMode _defaultBindingMode; /// /// Initializes a new instance of the class. /// /// The default binding mode. /// Whether the property is interested in data validation. public AvaloniaPropertyMetadata( BindingMode defaultBindingMode = BindingMode.Default, bool? enableDataValidation = null) { _defaultBindingMode = defaultBindingMode; EnableDataValidation = enableDataValidation; } /// /// Gets the default binding mode for the property. /// public BindingMode DefaultBindingMode { get { return _defaultBindingMode == BindingMode.Default ? BindingMode.OneWay : _defaultBindingMode; } } /// /// Gets a value indicating whether the property is interested in data validation. /// /// /// Data validation is validation performed at the target of a binding, for example in a /// view model using the INotifyDataErrorInfo interface. Only certain properties on a /// control (such as a TextBox's Text property) will be interested in receiving data /// validation messages so this feature must be explicitly enabled by setting this flag. /// public bool? EnableDataValidation { get; private set; } /// /// Merges the metadata with the base metadata. /// /// The base metadata to merge. /// The property to which the metadata is being applied. public virtual void Merge( AvaloniaPropertyMetadata baseMetadata, AvaloniaProperty property) { if (_defaultBindingMode == BindingMode.Default) { _defaultBindingMode = baseMetadata.DefaultBindingMode; } EnableDataValidation ??= baseMetadata.EnableDataValidation; } /// /// Gets a copy of this object configured for use with any owner type. /// /// /// For example, delegates which receive the owner object should be removed. /// public abstract AvaloniaPropertyMetadata GenerateTypeSafeMetadata(); } }