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