feat: make property context friendly.
This commit is contained in:
@@ -14,13 +14,13 @@
|
||||
</Style>
|
||||
</UserControl.Styles>
|
||||
<StackPanel HorizontalAlignment="Left">
|
||||
<u:NumericIntUpDown Name="input" Step="1" Value="2" Watermark="Input Value" />
|
||||
<u:NumericIntUpDown Name="input" Step="1" Value="2" Watermark="Input Value" IsReadOnly="True" />
|
||||
<TextBlock Text="{Binding #input.Value}" ></TextBlock>
|
||||
<u:NumericDoubleUpDown Name="inputDouble" Step="0.5" Value="3.1" EmptyInputValue="1"></u:NumericDoubleUpDown>
|
||||
<TextBlock Text="{Binding #inputDouble.Value}"></TextBlock>
|
||||
<u:NumericByteUpDown Name="inputByte" Step="1" Value="3" EmptyInputValue="1"></u:NumericByteUpDown>
|
||||
<TextBlock Text="{Binding #inputByte.Value}"></TextBlock>
|
||||
<TextBlock Text="Drag"></TextBlock>
|
||||
<u:NumericIntUpDown Step="1" Value="2" Watermark="Input Value" IsTextEditable="False" />
|
||||
<u:NumericIntUpDown Step="1" Value="2" Watermark="Input Value" AllowDrag="True" />
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
||||
@@ -38,8 +38,7 @@
|
||||
VerticalAlignment="Stretch"
|
||||
Background="Transparent"
|
||||
Cursor="SizeAll"
|
||||
IsVisible="{TemplateBinding IsTextEditable,
|
||||
Converter={x:Static BoolConverters.Not}}" />
|
||||
IsVisible="{TemplateBinding AllowDrag}" />
|
||||
</Panel>
|
||||
</ButtonSpinner>
|
||||
</DataValidationErrors>
|
||||
|
||||
@@ -27,13 +27,13 @@ public abstract class NumericUpDown : TemplatedControl
|
||||
private Point? _point;
|
||||
protected internal bool _updateFromTextInput;
|
||||
|
||||
public static readonly StyledProperty<bool> IsTextEditableProperty = AvaloniaProperty.Register<NumericUpDown, bool>(
|
||||
nameof(IsTextEditable), defaultValue: true);
|
||||
public static readonly StyledProperty<bool> AllowDragProperty = AvaloniaProperty.Register<NumericUpDown, bool>(
|
||||
nameof(AllowDrag), defaultValue: false);
|
||||
|
||||
public bool IsTextEditable
|
||||
public bool AllowDrag
|
||||
{
|
||||
get => GetValue(IsTextEditableProperty);
|
||||
set => SetValue(IsTextEditableProperty, value);
|
||||
get => GetValue(AllowDragProperty);
|
||||
set => SetValue(AllowDragProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<bool> IsReadOnlyProperty = AvaloniaProperty.Register<NumericUpDown, bool>(
|
||||
@@ -183,6 +183,10 @@ public abstract class NumericUpDown : TemplatedControl
|
||||
{
|
||||
CommitInput(true);
|
||||
base.OnLostFocus(e);
|
||||
if(AllowDrag && _dragPanel is not null)
|
||||
{
|
||||
_dragPanel.IsVisible = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
@@ -192,11 +196,23 @@ public abstract class NumericUpDown : TemplatedControl
|
||||
var commitSuccess = CommitInput(true);
|
||||
e.Handled = !commitSuccess;
|
||||
}
|
||||
|
||||
if (e.Key == Key.Escape)
|
||||
{
|
||||
if (AllowDrag && _dragPanel is not null)
|
||||
{
|
||||
_dragPanel.IsVisible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDragPanelPointerPressed(object sender, PointerPressedEventArgs e)
|
||||
{
|
||||
_point = e.GetPosition(this);
|
||||
if (e.ClickCount == 2 && _dragPanel is not null && AllowDrag)
|
||||
{
|
||||
_dragPanel.IsVisible = false;
|
||||
}
|
||||
_textBox?.Focus();
|
||||
}
|
||||
|
||||
@@ -207,7 +223,7 @@ public abstract class NumericUpDown : TemplatedControl
|
||||
|
||||
private void OnDragPanelPointerMoved(object sender, PointerEventArgs e)
|
||||
{
|
||||
if (IsTextEditable) return;
|
||||
if (!AllowDrag) return;
|
||||
if(!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;
|
||||
var point = e.GetPosition(this);
|
||||
var delta = point - _point;
|
||||
@@ -420,6 +436,7 @@ public abstract class NumericUpDownBase<T>: NumericUpDown where T: struct, IComp
|
||||
{
|
||||
_textBox.Text = ConvertValueToText(Value);
|
||||
}
|
||||
SetValidSpinDirection();
|
||||
}
|
||||
|
||||
protected virtual T? Clamp(T? value, T max, T min)
|
||||
|
||||
Reference in New Issue
Block a user