using System; using Avalonia.Data; namespace Avalonia { /// /// Metadata for styled avalonia properties. /// public class StyledPropertyMetadata : AvaloniaPropertyMetadata, IStyledPropertyMetadata { private Optional _defaultValue; /// /// Initializes a new instance of the class. /// /// The default value of the property. /// The default binding mode. /// A value coercion callback. public StyledPropertyMetadata( Optional defaultValue = default, BindingMode defaultBindingMode = BindingMode.Default, Func coerce = null) : base(defaultBindingMode) { _defaultValue = defaultValue; CoerceValue = coerce; } /// /// Gets the default value for the property. /// public TValue DefaultValue => _defaultValue.GetValueOrDefault(); /// /// Gets the value coercion callback, if any. /// public Func CoerceValue { get; private set; } object IStyledPropertyMetadata.DefaultValue => DefaultValue; /// public override void Merge(AvaloniaPropertyMetadata baseMetadata, AvaloniaProperty property) { base.Merge(baseMetadata, property); if (baseMetadata is StyledPropertyMetadata src) { if (!_defaultValue.HasValue) { _defaultValue = src.DefaultValue; } if (CoerceValue == null) { CoerceValue = src.CoerceValue; } } } } }