diff --git a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj index b84b674df..72aa0b92d 100644 --- a/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj +++ b/src/Artemis.UI.Shared/Artemis.UI.Shared.csproj @@ -17,7 +17,7 @@ - + diff --git a/src/Artemis.UI.Shared/Controls/DraggableNumberBox.axaml b/src/Artemis.UI.Shared/Controls/DraggableNumberBox.axaml index 23dc24c10..d480b0c51 100644 --- a/src/Artemis.UI.Shared/Controls/DraggableNumberBox.axaml +++ b/src/Artemis.UI.Shared/Controls/DraggableNumberBox.axaml @@ -25,15 +25,13 @@ + HorizontalAlignment="{Binding $parent[sharedControls:DraggableNumberBox].HorizontalAlignment}" + ValueChanged="NumberBox_OnValueChanged"/> diff --git a/src/Artemis.UI.Shared/Controls/DraggableNumberBox.axaml.cs b/src/Artemis.UI.Shared/Controls/DraggableNumberBox.axaml.cs index 6f83c0e8b..d3b5ca9ab 100644 --- a/src/Artemis.UI.Shared/Controls/DraggableNumberBox.axaml.cs +++ b/src/Artemis.UI.Shared/Controls/DraggableNumberBox.axaml.cs @@ -19,17 +19,31 @@ public class DraggableNumberBox : UserControl /// /// Defines the property. /// - public static readonly StyledProperty ValueProperty = AvaloniaProperty.Register(nameof(Value), defaultBindingMode: BindingMode.TwoWay); + public static readonly StyledProperty ValueProperty = AvaloniaProperty.Register(nameof(Value), defaultBindingMode: BindingMode.TwoWay, notifying: ValueChanged); + + private static void ValueChanged(IAvaloniaObject sender, bool before) + { + if (before) + return; + + DraggableNumberBox draggable = (DraggableNumberBox) sender; + if (!(Math.Abs(draggable._numberBox.Value - draggable.Value) > 0.00001)) + return; + + draggable._updating = true; + draggable._numberBox.Value = draggable.Value; + draggable._updating = false; + } /// /// Defines the property. /// - public static readonly StyledProperty MinimumProperty = AvaloniaProperty.Register(nameof(Minimum)); + public static readonly StyledProperty MinimumProperty = AvaloniaProperty.Register(nameof(Minimum), double.MinValue); /// /// Defines the property. /// - public static readonly StyledProperty MaximumProperty = AvaloniaProperty.Register(nameof(Maximum)); + public static readonly StyledProperty MaximumProperty = AvaloniaProperty.Register(nameof(Maximum), double.MaxValue); /// /// Defines the property. @@ -61,6 +75,7 @@ public class DraggableNumberBox : UserControl private double _lastX; private bool _moved; private double _startX; + private bool _updating; /// /// Creates a new instance of the class. @@ -69,6 +84,7 @@ public class DraggableNumberBox : UserControl { InitializeComponent(); _numberBox = this.Get("NumberBox"); + _numberBox.Value = Value; PointerPressed += OnPointerPressed; PointerMoved += OnPointerMoved; @@ -237,4 +253,25 @@ public class DraggableNumberBox : UserControl e.Handled = true; } + + private void NumberBox_OnValueChanged(NumberBox sender, NumberBoxValueChangedEventArgs args) + { + if (_updating) + return; + + if (args.NewValue < Minimum) + { + _numberBox.Value = Minimum; + return; + } + + if (args.NewValue > Maximum) + { + _numberBox.Value = Maximum; + return; + } + + if (Math.Abs(Value - _numberBox.Value) > 0.00001) + Value = _numberBox.Value; + } } \ No newline at end of file