add HorizontalContentAlignment
This commit is contained in:
@@ -50,6 +50,7 @@
|
|||||||
DataValidationErrors.Errors="{ReflectionBinding $parent[NumericUpDown].(DataValidationErrors.Errors)}"
|
DataValidationErrors.Errors="{ReflectionBinding $parent[NumericUpDown].(DataValidationErrors.Errors)}"
|
||||||
FontSize="{TemplateBinding FontSize}"
|
FontSize="{TemplateBinding FontSize}"
|
||||||
Foreground="{TemplateBinding Foreground}"
|
Foreground="{TemplateBinding Foreground}"
|
||||||
|
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||||
IsReadOnly="{TemplateBinding IsReadOnly}"
|
IsReadOnly="{TemplateBinding IsReadOnly}"
|
||||||
TextWrapping="NoWrap"
|
TextWrapping="NoWrap"
|
||||||
InnerLeftContent="{TemplateBinding InnerLeftContent}"
|
InnerLeftContent="{TemplateBinding InnerLeftContent}"
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using Avalonia.Data;
|
|||||||
using Avalonia.Data.Converters;
|
using Avalonia.Data.Converters;
|
||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
|
using Avalonia.Layout;
|
||||||
using Irihi.Avalonia.Shared.Contracts;
|
using Irihi.Avalonia.Shared.Contracts;
|
||||||
|
|
||||||
namespace Ursa.Controls;
|
namespace Ursa.Controls;
|
||||||
@@ -47,6 +48,15 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl
|
|||||||
set => SetValue(IsReadOnlyProperty, value);
|
set => SetValue(IsReadOnlyProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static readonly StyledProperty<HorizontalAlignment> HorizontalContentAlignmentProperty = AvaloniaProperty.Register<NumericUpDown, HorizontalAlignment>(
|
||||||
|
nameof(HorizontalContentAlignment), HorizontalAlignment.Left);
|
||||||
|
|
||||||
|
public HorizontalAlignment HorizontalContentAlignment
|
||||||
|
{
|
||||||
|
get => GetValue(HorizontalContentAlignmentProperty);
|
||||||
|
set => SetValue(HorizontalContentAlignmentProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
public static readonly StyledProperty<object?> InnerLeftContentProperty = AvaloniaProperty.Register<NumericUpDown, object?>(
|
public static readonly StyledProperty<object?> InnerLeftContentProperty = AvaloniaProperty.Register<NumericUpDown, object?>(
|
||||||
nameof(InnerLeftContent));
|
nameof(InnerLeftContent));
|
||||||
|
|
||||||
@@ -125,7 +135,7 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl
|
|||||||
{
|
{
|
||||||
NumberFormatProperty.Changed.AddClassHandler<NumericUpDown>((o, e) => o.OnFormatChange(e));
|
NumberFormatProperty.Changed.AddClassHandler<NumericUpDown>((o, e) => o.OnFormatChange(e));
|
||||||
FormatStringProperty.Changed.AddClassHandler<NumericUpDown>((o, e) => o.OnFormatChange(e));
|
FormatStringProperty.Changed.AddClassHandler<NumericUpDown>((o, e) => o.OnFormatChange(e));
|
||||||
IsReadOnlyProperty.Changed.AddClassHandler<NumericUpDown>((o,e)=>o.ChangeToSetSpinDirection(e));
|
IsReadOnlyProperty.Changed.AddClassHandler<NumericUpDown>((o, e) => o.ChangeToSetSpinDirection(e));
|
||||||
TextConverterProperty.Changed.AddClassHandler<NumericUpDown>((o, e) => o.OnFormatChange(e));
|
TextConverterProperty.Changed.AddClassHandler<NumericUpDown>((o, e) => o.OnFormatChange(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +165,7 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl
|
|||||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnApplyTemplate(e);
|
base.OnApplyTemplate(e);
|
||||||
if(_spinner is not null)
|
if (_spinner is not null)
|
||||||
{
|
{
|
||||||
_spinner.Spin -= OnSpin;
|
_spinner.Spin -= OnSpin;
|
||||||
}
|
}
|
||||||
@@ -174,7 +184,7 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl
|
|||||||
}
|
}
|
||||||
if (_dragPanel is not null)
|
if (_dragPanel is not null)
|
||||||
{
|
{
|
||||||
_dragPanel.PointerPressed+= OnDragPanelPointerPressed;
|
_dragPanel.PointerPressed += OnDragPanelPointerPressed;
|
||||||
_dragPanel.PointerMoved += OnDragPanelPointerMoved;
|
_dragPanel.PointerMoved += OnDragPanelPointerMoved;
|
||||||
_dragPanel.PointerReleased += OnDragPanelPointerReleased;
|
_dragPanel.PointerReleased += OnDragPanelPointerReleased;
|
||||||
}
|
}
|
||||||
@@ -185,7 +195,7 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl
|
|||||||
{
|
{
|
||||||
CommitInput(true);
|
CommitInput(true);
|
||||||
base.OnLostFocus(e);
|
base.OnLostFocus(e);
|
||||||
if(AllowDrag && _dragPanel is not null)
|
if (AllowDrag && _dragPanel is not null)
|
||||||
{
|
{
|
||||||
_dragPanel.IsVisible = true;
|
_dragPanel.IsVisible = true;
|
||||||
}
|
}
|
||||||
@@ -237,7 +247,7 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl
|
|||||||
private void OnDragPanelPointerMoved(object sender, PointerEventArgs e)
|
private void OnDragPanelPointerMoved(object sender, PointerEventArgs e)
|
||||||
{
|
{
|
||||||
if (!AllowDrag || IsReadOnly) return;
|
if (!AllowDrag || IsReadOnly) 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;
|
||||||
if (delta is null)
|
if (delta is null)
|
||||||
@@ -245,7 +255,7 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int d = GetDelta(delta.Value);
|
int d = GetDelta(delta.Value);
|
||||||
if(d > 0)
|
if (d > 0)
|
||||||
{
|
{
|
||||||
Increase();
|
Increase();
|
||||||
}
|
}
|
||||||
@@ -307,7 +317,7 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl
|
|||||||
public abstract void Clear();
|
public abstract void Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class NumericUpDownBase<T>: NumericUpDown where T: struct, IComparable<T>
|
public abstract class NumericUpDownBase<T> : NumericUpDown where T : struct, IComparable<T>
|
||||||
{
|
{
|
||||||
public static readonly StyledProperty<T?> ValueProperty = AvaloniaProperty.Register<NumericUpDownBase<T>, T?>(
|
public static readonly StyledProperty<T?> ValueProperty = AvaloniaProperty.Register<NumericUpDownBase<T>, T?>(
|
||||||
nameof(Value), defaultBindingMode: BindingMode.TwoWay);
|
nameof(Value), defaultBindingMode: BindingMode.TwoWay);
|
||||||
@@ -319,7 +329,7 @@ public abstract class NumericUpDownBase<T>: NumericUpDown where T: struct, IComp
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static readonly StyledProperty<T> MaximumProperty = AvaloniaProperty.Register<NumericUpDownBase<T>, T>(
|
public static readonly StyledProperty<T> MaximumProperty = AvaloniaProperty.Register<NumericUpDownBase<T>, T>(
|
||||||
nameof(Maximum), defaultBindingMode:BindingMode.TwoWay, coerce: CoerceMaximum);
|
nameof(Maximum), defaultBindingMode: BindingMode.TwoWay, coerce: CoerceMaximum);
|
||||||
|
|
||||||
public T Maximum
|
public T Maximum
|
||||||
{
|
{
|
||||||
@@ -328,7 +338,7 @@ public abstract class NumericUpDownBase<T>: NumericUpDown where T: struct, IComp
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static readonly StyledProperty<T> MinimumProperty = AvaloniaProperty.Register<NumericUpDownBase<T>, T>(
|
public static readonly StyledProperty<T> MinimumProperty = AvaloniaProperty.Register<NumericUpDownBase<T>, T>(
|
||||||
nameof(Minimum), defaultBindingMode:BindingMode.TwoWay, coerce: CoerceMinimum);
|
nameof(Minimum), defaultBindingMode: BindingMode.TwoWay, coerce: CoerceMinimum);
|
||||||
|
|
||||||
public T Minimum
|
public T Minimum
|
||||||
{
|
{
|
||||||
@@ -416,7 +426,7 @@ public abstract class NumericUpDownBase<T>: NumericUpDown where T: struct, IComp
|
|||||||
StepProperty.Changed.AddClassHandler<NumericUpDownBase<T>>((o, e) => o.ChangeToSetSpinDirection(e));
|
StepProperty.Changed.AddClassHandler<NumericUpDownBase<T>>((o, e) => o.ChangeToSetSpinDirection(e));
|
||||||
MaximumProperty.Changed.AddClassHandler<NumericUpDownBase<T>>((o, e) => o.OnConstraintChanged(e));
|
MaximumProperty.Changed.AddClassHandler<NumericUpDownBase<T>>((o, e) => o.OnConstraintChanged(e));
|
||||||
MinimumProperty.Changed.AddClassHandler<NumericUpDownBase<T>>((o, e) => o.OnConstraintChanged(e));
|
MinimumProperty.Changed.AddClassHandler<NumericUpDownBase<T>>((o, e) => o.OnConstraintChanged(e));
|
||||||
ValueProperty.Changed.AddClassHandler<NumericUpDownBase<T>>((o, e) => o.OnValueChanged(e) );
|
ValueProperty.Changed.AddClassHandler<NumericUpDownBase<T>>((o, e) => o.OnValueChanged(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnConstraintChanged(AvaloniaPropertyChangedEventArgs avaloniaPropertyChangedEventArgs)
|
private void OnConstraintChanged(AvaloniaPropertyChangedEventArgs avaloniaPropertyChangedEventArgs)
|
||||||
@@ -530,7 +540,7 @@ public abstract class NumericUpDownBase<T>: NumericUpDown where T: struct, IComp
|
|||||||
if (forceTextUpdate)
|
if (forceTextUpdate)
|
||||||
{
|
{
|
||||||
var newText = ConvertValueToText(Value);
|
var newText = ConvertValueToText(Value);
|
||||||
if (_textBox!= null && !Equals(_textBox.Text, newText))
|
if (_textBox != null && !Equals(_textBox.Text, newText))
|
||||||
{
|
{
|
||||||
_textBox.Text = newText;
|
_textBox.Text = newText;
|
||||||
_textBox.CaretIndex = newText?.Length ?? 0;
|
_textBox.CaretIndex = newText?.Length ?? 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user