1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +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,7 +68,6 @@ public partial class DraggableNumberBox : UserControl
public DraggableNumberBox()
{
InitializeComponent();
InnerNumberBox.Value = Value;
PointerPressed += OnPointerPressed;
PointerMoved += OnPointerMoved;
@ -160,6 +159,21 @@ public partial class DraggableNumberBox : UserControl
/// </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))
@ -250,7 +264,7 @@ public partial class DraggableNumberBox : UserControl
SetNumberBoxValue(Value);
}
private void NumberBox_OnValueChanged(NumberBox sender, NumberBoxValueChangedEventArgs args)
private void InnerNumberBoxOnValueChanged(NumberBox sender, NumberBoxValueChangedEventArgs args)
{
if (_updating)
return;