using Avalonia.Data;
namespace Avalonia
{
///
/// Metadata for direct avalonia properties.
///
public class DirectPropertyMetadata : AvaloniaPropertyMetadata, IDirectPropertyMetadata
{
///
/// Initializes a new instance of the class.
///
///
/// The value to use when the property is set to
///
/// The default binding mode.
///
/// Whether the property is interested in data validation.
///
public DirectPropertyMetadata(
TValue unsetValue = default(TValue),
BindingMode defaultBindingMode = BindingMode.Default,
bool? enableDataValidation = null)
: base(defaultBindingMode)
{
UnsetValue = unsetValue;
EnableDataValidation = enableDataValidation;
}
///
/// Gets the value to use when the property is set to .
///
public TValue UnsetValue { get; private set; }
///
/// 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 recieving data
/// validation messages so this feature must be explicitly enabled by setting this flag.
///
public bool? EnableDataValidation { get; private set; }
///
object IDirectPropertyMetadata.UnsetValue => UnsetValue;
///
public override void Merge(AvaloniaPropertyMetadata baseMetadata, AvaloniaProperty property)
{
base.Merge(baseMetadata, property);
var src = baseMetadata as DirectPropertyMetadata;
if (src != null)
{
if (UnsetValue == null)
{
UnsetValue = src.UnsetValue;
}
if (EnableDataValidation == null)
{
EnableDataValidation = src.EnableDataValidation;
}
}
}
}
}