feat: add validation errors to NumericUpDown.

This commit is contained in:
Zhang Dian 2023-05-06 21:54:35 +08:00
parent 45f3470d76
commit d75a4c549e
2 changed files with 51 additions and 36 deletions

View File

@ -8,17 +8,12 @@
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<StackPanel HorizontalAlignment="Left">
<StackPanel HorizontalAlignment="Left" Spacing="20">
<AutoCompleteBox Width="300">
<DataValidationErrors.Error>
<system:Exception />
</DataValidationErrors.Error>
</AutoCompleteBox>
<ButtonSpinner Width="300">
<DataValidationErrors.Error>
<system:Exception />
</DataValidationErrors.Error>
</ButtonSpinner>
<CalendarDatePicker Width="300">
<DataValidationErrors.Error>
<system:Exception />

View File

@ -5,10 +5,10 @@
<!-- Add Resources Here -->
<ControlTheme x:Key="{x:Type NumericUpDown}" TargetType="NumericUpDown">
<Setter Property="NumericUpDown.VerticalContentAlignment" Value="Center" />
<Setter Property="NumericUpDown.MinHeight" Value="{DynamicResource NumericUpDownWrapperDefaultHeight}" />
<Setter Property="NumericUpDown.CornerRadius" Value="{DynamicResource NumericUpDownCornerRadius}" />
<Setter Property="NumericUpDown.Template">
<ControlTemplate TargetType="NumericUpDown">
<DataValidationErrors>
<ButtonSpinner
Name="PART_Spinner"
MinWidth="0"
@ -23,7 +23,7 @@
<TextBox
Name="PART_TextBox"
Height="{TemplateBinding Height}"
MinHeight="{TemplateBinding MinHeight}"
MinHeight="{DynamicResource NumericUpDownWrapperDefaultHeight}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
AcceptsReturn="False"
@ -35,15 +35,35 @@
TextWrapping="NoWrap"
Watermark="{TemplateBinding Watermark}" />
</ButtonSpinner>
</DataValidationErrors>
</ControlTemplate>
</Setter>
<Style Selector="^.Large">
<Style Selector="^.Large /template/ TextBox#PART_TextBox">
<Setter Property="MinHeight" Value="{DynamicResource NumericUpDownWrapperLargeHeight}" />
</Style>
<Style Selector="^.Small">
<Style Selector="^.Small /template/ TextBox#PART_TextBox">
<Setter Property="MinHeight" Value="{DynamicResource NumericUpDownWrapperSmallHeight}" />
</Style>
<Style Selector="^:error">
<Style Selector="^ /template/ TextBox#PART_TextBox">
<Setter Property="Background" Value="{DynamicResource DataValidationErrorsBackground}" />
<Setter Property="BorderBrush" Value="Transparent" />
</Style>
<Style Selector="^:pointerover /template/ TextBox#PART_TextBox">
<Setter Property="Background" Value="{DynamicResource DataValidationErrorsPointerOverBackground}" />
<Setter Property="BorderBrush" Value="Transparent" />
</Style>
<Style Selector="^:pressed /template/ TextBox#PART_TextBox">
<Setter Property="Background" Value="{DynamicResource DataValidationErrorsPressedBackground}" />
<Setter Property="BorderBrush" Value="Transparent" />
</Style>
<Style Selector="^:focus /template/ TextBox#PART_TextBox">
<Setter Property="Background" Value="{DynamicResource DataValidationErrorsSelectedBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource DataValidationErrorsSelectedBorderBrush}" />
</Style>
</Style>
</ControlTheme>
</ResourceDictionary>