using Avalonia.Controls; using System; namespace MapControl { [System.Diagnostics.CodeAnalysis.SuppressMessage("AvaloniaProperty", "AVP1001")] public static class DependencyPropertyHelper { public static StyledProperty Register( string name, TValue defaultValue = default, bool bindTwoWayByDefault = false, Action changed = null, Func coerce = null) where TOwner : AvaloniaObject { var property = AvaloniaProperty.Register(name, defaultValue, false, bindTwoWayByDefault ? Avalonia.Data.BindingMode.TwoWay : Avalonia.Data.BindingMode.OneWay, null, coerce != null ? ((obj, value) => coerce((TOwner)obj, value)) : null); if (changed != null) { property.Changed.AddClassHandler((o, e) => changed(o, e.OldValue.Value, e.NewValue.Value)); } return property; } public static AttachedProperty RegisterAttached( string name, TValue defaultValue = default, bool inherits = false, Action changed = null) where TOwner : AvaloniaObject { var property = AvaloniaProperty.RegisterAttached(name, defaultValue, inherits); if (changed != null) { property.Changed.AddClassHandler((o, e) => changed(o, e.OldValue.Value, e.NewValue.Value)); } return property; } public static DirectProperty RegisterReadOnly( string name, Func getter) where TOwner : AvaloniaObject { return AvaloniaProperty.RegisterDirect(name, getter); } } }