1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 13:28:33 +00:00

UI - Fix draggable number box clamping the value to 0-100 when unloading

This commit is contained in:
Robert 2023-05-22 20:19:42 +02:00
parent ec594f02b1
commit dc8147d5a7
2 changed files with 22 additions and 9 deletions

View File

@ -32,8 +32,7 @@
SimpleNumberFormat="{CompiledBinding $parent[sharedControls:DraggableNumberBox].SimpleNumberFormat}"
attachedProperties:NumberBoxAssist.PrefixText="{CompiledBinding $parent[sharedControls:DraggableNumberBox].Prefix}"
attachedProperties:NumberBoxAssist.SuffixText="{CompiledBinding $parent[sharedControls:DraggableNumberBox].Suffix}"
HorizontalAlignment="{CompiledBinding $parent[sharedControls:DraggableNumberBox].HorizontalAlignment}"
ValueChanged="NumberBox_OnValueChanged"/>
HorizontalAlignment="{CompiledBinding $parent[sharedControls:DraggableNumberBox].HorizontalAlignment}"/>
<Rectangle Name="DragCollider" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Fill="Transparent"></Rectangle>
</Panel>

View File

@ -4,7 +4,7 @@ using Avalonia.Controls;
using Avalonia.Data;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.LogicalTree;
using Avalonia.VisualTree;
using FluentAvalonia.Core;
using FluentAvalonia.UI.Controls;
@ -68,13 +68,12 @@ public partial class DraggableNumberBox : UserControl
public DraggableNumberBox()
{
InitializeComponent();
InnerNumberBox.Value = Value;
PointerPressed += OnPointerPressed;
PointerMoved += OnPointerMoved;
PointerReleased += OnPointerReleased;
PropertyChanged += OnPropertyChanged;
AddHandler(KeyUpEvent, HandleKeyUp, RoutingStrategies.Direct | RoutingStrategies.Tunnel | RoutingStrategies.Bubble, true);
}
@ -159,7 +158,22 @@ public partial class DraggableNumberBox : UserControl
/// Occurs when the user finishes dragging over the control.
/// </summary>
public event TypedEventHandler<DraggableNumberBox, EventArgs>? DragFinished;
/// <inheritdoc />
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
{
InnerNumberBox.Value = Value;
InnerNumberBox.ValueChanged += InnerNumberBoxOnValueChanged;
base.OnAttachedToLogicalTree(e);
}
/// <inheritdoc />
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
{
InnerNumberBox.ValueChanged -= InnerNumberBoxOnValueChanged;
base.OnDetachedFromLogicalTree(e);
}
private void SetNumberBoxValue(double value)
{
if (!(Math.Abs(InnerNumberBox.Value - Value) > 0.00001))
@ -243,14 +257,14 @@ public partial class DraggableNumberBox : UserControl
e.Handled = true;
}
private void OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
{
if (e.Property == ValueProperty)
SetNumberBoxValue(Value);
}
private void NumberBox_OnValueChanged(NumberBox sender, NumberBoxValueChangedEventArgs args)
private void InnerNumberBoxOnValueChanged(NumberBox sender, NumberBoxValueChangedEventArgs args)
{
if (_updating)
return;