hc:NumericUpDown support for Validation
This commit is contained in:
1 parent
697b5e0014
commit
ac8b5561a5
2 files changed
+24
-6
No files matched your search
@@ -112,12 +112,28 @@ namespace HandyControl.Controls
|
|||||||
_updateText = true;
|
_updateText = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (double.TryParse(_textBox.Text, out var value))
|
|
||||||
|
_updateText = false;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(_textBox.Text))
|
||||||
{
|
{
|
||||||
_updateText = false;
|
Value = 0;
|
||||||
Value = value;
|
|
||||||
_updateText = true;
|
SetCurrentValue(ErrorStrProperty, string.Empty);
|
||||||
|
SetCurrentValue(IsErrorProperty, false);
|
||||||
}
|
}
|
||||||
|
else if (double.TryParse(_textBox.Text, out var value))
|
||||||
|
{
|
||||||
|
Value = value;
|
||||||
|
|
||||||
|
if (Validation.GetHasError(this))
|
||||||
|
{
|
||||||
|
SetCurrentValue(ErrorStrProperty, Validation.GetErrors(this)[0].ErrorContent);
|
||||||
|
SetCurrentValue(IsErrorProperty, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_updateText = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PreviewTextInputHandler(object sender, TextCompositionEventArgs e) => UpdateData();
|
private void PreviewTextInputHandler(object sender, TextCompositionEventArgs e) => UpdateData();
|
||||||
@@ -496,8 +512,8 @@ namespace HandyControl.Controls
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IsError = !result.Data;
|
SetCurrentValue(ErrorStrProperty, result.Message);
|
||||||
ErrorStr = result.Message;
|
SetCurrentValue(IsErrorProperty, !result.Data);
|
||||||
return result.Data;
|
return result.Data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
|
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
|
||||||
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
|
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
|
||||||
<Setter Property="VerticalContentAlignment" Value="Center"/>
|
<Setter Property="VerticalContentAlignment" Value="Center"/>
|
||||||
|
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}"/>
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<ControlTemplate TargetType="hc:NumericUpDown">
|
<ControlTemplate TargetType="hc:NumericUpDown">
|
||||||
@@ -285,6 +286,7 @@
|
|||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
|
|
||||||
<Style x:Key="NumericUpDownPlusBaseStyle" BasedOn="{StaticResource NumericUpDownExtendBaseStyle}" TargetType="hc:NumericUpDown">
|
<Style x:Key="NumericUpDownPlusBaseStyle" BasedOn="{StaticResource NumericUpDownExtendBaseStyle}" TargetType="hc:NumericUpDown">
|
||||||
|
<Setter Property="IsError" Value="{Binding Path=(Validation.HasError),RelativeSource={RelativeSource Self}}"/>
|
||||||
<Setter Property="Template" Value="{StaticResource NumericUpDownPlusTopTemplate}"/>
|
<Setter Property="Template" Value="{StaticResource NumericUpDownPlusTopTemplate}"/>
|
||||||
<Style.Triggers>
|
<Style.Triggers>
|
||||||
<Trigger Property="hc:InfoElement.TitlePlacement" Value="Left">
|
<Trigger Property="hc:InfoElement.TitlePlacement" Value="Left">
|
||||||
|
|||||||
Reference in new issue
Block a user