Merge pull request #314 from irihitech/numeirc-validation
Fix: fix numeric updown validation error display issue
This commit is contained in:
@@ -41,6 +41,7 @@
|
|||||||
Width="300"
|
Width="300"
|
||||||
u:FormItem.Label="Email"
|
u:FormItem.Label="Email"
|
||||||
Text="{Binding Email}" />
|
Text="{Binding Email}" />
|
||||||
|
<u:NumericDoubleUpDown Value="{Binding Number}" u:FormItem.Label="Number" Width="300"/>
|
||||||
</u:FormGroup>
|
</u:FormGroup>
|
||||||
<u:FormItem Label="Please select a Date">
|
<u:FormItem Label="Please select a Date">
|
||||||
<CalendarDatePicker SelectedDate="{Binding Date}" />
|
<CalendarDatePicker SelectedDate="{Binding Date}" />
|
||||||
|
|||||||
@@ -24,6 +24,14 @@ public partial class DataModel : ObservableObject
|
|||||||
get=>_name;
|
get=>_name;
|
||||||
set => SetProperty(ref _name, value);
|
set => SetProperty(ref _name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private double _number;
|
||||||
|
[Range(0.0, 10.0)]
|
||||||
|
public double Number
|
||||||
|
{
|
||||||
|
get => _number;
|
||||||
|
set => SetProperty(ref _number, value);
|
||||||
|
}
|
||||||
|
|
||||||
private string _email;
|
private string _email;
|
||||||
|
|
||||||
|
|||||||
@@ -380,7 +380,7 @@ public abstract class NumericUpDownBase<T> : NumericUpDown where T : struct, ICo
|
|||||||
}
|
}
|
||||||
|
|
||||||
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, enableDataValidation: true);
|
||||||
|
|
||||||
public T? Value
|
public T? Value
|
||||||
{
|
{
|
||||||
@@ -485,6 +485,15 @@ public abstract class NumericUpDownBase<T> : NumericUpDown where T : struct, ICo
|
|||||||
set => this.SetValue(CommandParameterProperty, value);
|
set => this.SetValue(CommandParameterProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void UpdateDataValidation(AvaloniaProperty property, BindingValueType state, Exception? error)
|
||||||
|
{
|
||||||
|
if (property == ValueProperty)
|
||||||
|
{
|
||||||
|
DataValidationErrors.SetError(this, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void InvokeCommand(object? cp)
|
private void InvokeCommand(object? cp)
|
||||||
{
|
{
|
||||||
if (this.Command != null && this.Command.CanExecute(cp))
|
if (this.Command != null && this.Command.CanExecute(cp))
|
||||||
|
|||||||
Reference in New Issue
Block a user