hc:DatePicker support for Validation

This commit is contained in:
NaBian 2021-07-18 14:25:53 +08:00
parent ac8b5561a5
commit 13d9404848
6 changed files with 23 additions and 9 deletions

View File

@ -188,7 +188,7 @@ namespace HandyControl.Controls
var isError = !result.Data;
if (isError)
{
SetCurrentValue(IsErrorProperty, true);
SetCurrentValue(IsErrorProperty, ValueBoxes.TrueBox);
SetCurrentValue(ErrorStrProperty, result.Message);
}
else

View File

@ -360,7 +360,7 @@ namespace HandyControl.Controls
var isError = !result.Data;
if (isError)
{
SetCurrentValue(IsErrorProperty, true);
SetCurrentValue(IsErrorProperty, ValueBoxes.TrueBox);
SetCurrentValue(ErrorStrProperty, result.Message);
}
else

View File

@ -153,9 +153,21 @@ namespace HandyControl.Controls
}
}
IsError = !result.Data;
ErrorStr = result.Message;
return result.Data;
var isError = !result.Data;
if (isError)
{
SetCurrentValue(IsErrorProperty, true);
SetCurrentValue(ErrorStrProperty, result.Message);
}
else
{
isError = Validation.GetHasError(this);
if (isError)
{
SetCurrentValue(ErrorStrProperty, Validation.GetErrors(this)[0].ErrorContent);
}
}
return !isError;
}
}
}

View File

@ -120,7 +120,7 @@ namespace HandyControl.Controls
Value = 0;
SetCurrentValue(ErrorStrProperty, string.Empty);
SetCurrentValue(IsErrorProperty, false);
SetCurrentValue(IsErrorProperty, ValueBoxes.FalseBox);
}
else if (double.TryParse(_textBox.Text, out var value))
{
@ -129,7 +129,7 @@ namespace HandyControl.Controls
if (Validation.GetHasError(this))
{
SetCurrentValue(ErrorStrProperty, Validation.GetErrors(this)[0].ErrorContent);
SetCurrentValue(IsErrorProperty, true);
SetCurrentValue(IsErrorProperty, ValueBoxes.TrueBox);
}
}
@ -513,7 +513,7 @@ namespace HandyControl.Controls
}
SetCurrentValue(ErrorStrProperty, result.Message);
SetCurrentValue(IsErrorProperty, !result.Data);
SetCurrentValue(IsErrorProperty, ValueBoxes.BooleanBox(!result.Data));
return result.Data;
}
}

View File

@ -115,7 +115,7 @@ namespace HandyControl.Controls
var isError = !result.Data;
if (isError)
{
SetCurrentValue(IsErrorProperty, true);
SetCurrentValue(IsErrorProperty, ValueBoxes.TrueBox);
SetCurrentValue(ErrorStrProperty, result.Message);
}
else

View File

@ -34,6 +34,7 @@
<Setter Property="Padding" Value="{StaticResource DefaultInputPadding}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DatePicker">
@ -343,6 +344,7 @@
</ControlTemplate>
<Style x:Key="DatePickerPlusBaseStyle" BasedOn="{StaticResource DatePickerExtendBaseStyle}" TargetType="hc:DatePicker">
<Setter Property="IsError" Value="{Binding Path=(Validation.HasError),RelativeSource={RelativeSource Self}}"/>
<Setter Property="CaretBrush" Value="{DynamicResource PrimaryTextBrush}"/>
<Setter Property="Template" Value="{StaticResource DatePickerPlusTopTemplate}"/>
<Style.Triggers>