feat: add validation errors to CalendarDatePicker.

This commit is contained in:
Zhang Dian
2023-05-07 00:11:38 +08:00
parent ae0994aa93
commit cece722496

View File

@@ -34,96 +34,99 @@
<Setter Property="VerticalAlignment" Value="Center" /> <Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Left" /> <Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="CalendarDatePicker.MinHeight" Value="{DynamicResource CalendarDatePickerDefaultHeight}" />
<Setter Property="Padding" Value="8 0" /> <Setter Property="Padding" Value="8 0" />
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate TargetType="CalendarDatePicker"> <ControlTemplate TargetType="CalendarDatePicker">
<Panel <DataValidationErrors>
x:Name="LayoutRoot" <Panel
HorizontalAlignment="Stretch" x:Name="LayoutRoot"
VerticalAlignment="Stretch"> HorizontalAlignment="Stretch"
<Border VerticalAlignment="Stretch">
x:Name="Background" <Border
Background="{TemplateBinding Background}" x:Name="Background"
BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}"
BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}"
CornerRadius="{TemplateBinding CornerRadius}"> BorderThickness="{TemplateBinding BorderThickness}"
<Grid CornerRadius="{TemplateBinding CornerRadius}">
HorizontalAlignment="Stretch" <Grid
VerticalAlignment="Center"
ColumnDefinitions="*,Auto">
<TextBox
Name="PART_TextBox"
Grid.Column="0"
MinHeight="{DynamicResource CalendarDatePickerInnerDefaultHeight}"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
VerticalAlignment="Center" VerticalAlignment="Center"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" ColumnDefinitions="*,Auto">
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" <TextBox
Background="Transparent" Name="PART_TextBox"
BorderBrush="Transparent" Grid.Column="0"
BorderThickness="0" MinHeight="{DynamicResource CalendarDatePickerDefaultHeight}"
CornerRadius="{TemplateBinding CornerRadius}" HorizontalAlignment="Stretch"
Foreground="{TemplateBinding Foreground}" VerticalAlignment="Center"
UseFloatingWatermark="{TemplateBinding UseFloatingWatermark}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
Watermark="{TemplateBinding Watermark}"> VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
<TextBox.Styles> Background="Transparent"
<Style Selector="TextBox#PART_TextBox:pointerover /template/ Border#PART_ContentPresenterBorder"> BorderBrush="Transparent"
<!-- By default the TextBox has its own focused state, override this to disable it here --> BorderThickness="0"
<Setter Property="Background" Value="Transparent" /> CornerRadius="{TemplateBinding CornerRadius}"
<Setter Property="BorderBrush" Value="Transparent" /> Foreground="{TemplateBinding Foreground}"
<Setter Property="BorderThickness" Value="0" /> UseFloatingWatermark="{TemplateBinding UseFloatingWatermark}"
</Style> Watermark="{TemplateBinding Watermark}">
<Style Selector="TextBox#PART_TextBox:focus /template/ Border#PART_ContentPresenterBorder"> <TextBox.Styles>
<!-- By default the TextBox has its own focused state, override this to disable it here --> <Style
<Setter Property="Background" Value="Transparent" /> Selector="TextBox#PART_TextBox:pointerover /template/ Border#PART_ContentPresenterBorder">
<Setter Property="BorderBrush" Value="Transparent" /> <!-- By default the TextBox has its own focused state, override this to disable it here -->
<Setter Property="BorderThickness" Value="0" />
</Style>
<Style Selector="TextBox#PART_TextBox:disabled">
<Style Selector="^ /template/ Border#PART_ContentPresenterBorder">
<!-- By default the TextBox has its own disabled state, override this to make the border background show through -->
<Setter Property="Background" Value="Transparent" /> <Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" /> <Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
</Style> </Style>
</Style> <Style
</TextBox.Styles> Selector="TextBox#PART_TextBox:focus /template/ Border#PART_ContentPresenterBorder">
</TextBox> <!-- By default the TextBox has its own focused state, override this to disable it here -->
<Button <Setter Property="Background" Value="Transparent" />
Name="PART_Button" <Setter Property="BorderBrush" Value="Transparent" />
Grid.Column="1" <Setter Property="BorderThickness" Value="0" />
Padding="0,0,8,0" </Style>
Cursor="Hand" <Style Selector="TextBox#PART_TextBox:disabled">
Focusable="False" <Style Selector="^ /template/ Border#PART_ContentPresenterBorder">
Theme="{DynamicResource CalendarDatePickerButton}" /> <!-- By default the TextBox has its own disabled state, override this to make the border background show through -->
<Popup <Setter Property="Background" Value="Transparent" />
Name="PART_Popup" <Setter Property="BorderBrush" Value="Transparent" />
HorizontalOffset="-8" </Style>
IsLightDismissEnabled="True" </Style>
PlacementTarget="{TemplateBinding}" </TextBox.Styles>
VerticalOffset="-4"> </TextBox>
<Border <Button
Margin="8" Name="PART_Button"
Background="Transparent" Grid.Column="1"
BoxShadow="{DynamicResource CalendarDatePickerPopupBoxShadows}" Padding="0,0,8,0"
CornerRadius="{DynamicResource CalendarCornerRadius}"> Cursor="Hand"
<Calendar Focusable="False"
Name="PART_Calendar" Theme="{DynamicResource CalendarDatePickerButton}" />
BorderThickness="0" <Popup
CornerRadius="{Binding $parent[Border].CornerRadius}" Name="PART_Popup"
DisplayDate="{TemplateBinding DisplayDate}" HorizontalOffset="-8"
DisplayDateEnd="{TemplateBinding DisplayDateEnd}" IsLightDismissEnabled="True"
DisplayDateStart="{TemplateBinding DisplayDateStart}" PlacementTarget="{TemplateBinding}"
FirstDayOfWeek="{TemplateBinding FirstDayOfWeek}" VerticalOffset="-4">
IsTodayHighlighted="{TemplateBinding IsTodayHighlighted}" <Border
SelectedDate="{TemplateBinding SelectedDate, Margin="8"
Mode=TwoWay}" /> Background="Transparent"
</Border> BoxShadow="{DynamicResource CalendarDatePickerPopupBoxShadows}"
</Popup> CornerRadius="{DynamicResource CalendarCornerRadius}">
</Grid> <Calendar
</Border> Name="PART_Calendar"
BorderThickness="0"
CornerRadius="{Binding $parent[Border].CornerRadius}"
DisplayDate="{TemplateBinding DisplayDate}"
DisplayDateEnd="{TemplateBinding DisplayDateEnd}"
DisplayDateStart="{TemplateBinding DisplayDateStart}"
FirstDayOfWeek="{TemplateBinding FirstDayOfWeek}"
IsTodayHighlighted="{TemplateBinding IsTodayHighlighted}"
SelectedDate="{TemplateBinding SelectedDate, Mode=TwoWay}" />
</Border>
</Popup>
</Grid>
</Border>
</Panel>
</DataValidationErrors>
</Panel>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
@@ -166,6 +169,25 @@
<Setter Property="BorderBrush" Value="{DynamicResource CalendarDatePickerFocusBorderBrush}" /> <Setter Property="BorderBrush" Value="{DynamicResource CalendarDatePickerFocusBorderBrush}" />
</Style> </Style>
<Style Selector="^:error">
<Style Selector="^ /template/ Border#Background">
<Setter Property="Background" Value="{DynamicResource DataValidationErrorsBackground}" />
<Setter Property="BorderBrush" Value="Transparent" />
</Style>
<Style Selector="^:pointerover /template/ Border#Background">
<Setter Property="Background" Value="{DynamicResource DataValidationErrorsPointerOverBackground}" />
<Setter Property="BorderBrush" Value="Transparent" />
</Style>
<Style Selector="^:pressed /template/ Border#Background">
<Setter Property="Background" Value="{DynamicResource DataValidationErrorsPressedBackground}" />
<Setter Property="BorderBrush" Value="Transparent" />
</Style>
<Style Selector="^:focus /template/ Border#Background">
<Setter Property="Background" Value="{DynamicResource DataValidationErrorsSelectedBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource DataValidationErrorsSelectedBorderBrush}" />
</Style>
</Style>
<Style Selector="^.Bordered"> <Style Selector="^.Bordered">
<Style Selector="^ Border#Background"> <Style Selector="^ Border#Background">
<Setter Property="Border.Background" Value="{DynamicResource CalendarDatePickerBorderedDefaultBackground}" /> <Setter Property="Border.Background" Value="{DynamicResource CalendarDatePickerBorderedDefaultBackground}" />
@@ -189,6 +211,24 @@
<Setter Property="Foreground" Value="{DynamicResource CalendarDatePickerDisabledIconForeground}" /> <Setter Property="Foreground" Value="{DynamicResource CalendarDatePickerDisabledIconForeground}" />
</Style> </Style>
</Style> </Style>
<Style Selector="^:error">
<Style Selector="^ /template/ Border#Background">
<Setter Property="Background" Value="{DynamicResource DataValidationErrorsBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource DataValidationErrorsBorderBrush}" />
</Style>
<Style Selector="^:pointerover /template/ Border#Background">
<Setter Property="Border.Background" Value="{DynamicResource DataValidationErrorsPointerOverBackground}" />
<Setter Property="Border.BorderBrush" Value="{DynamicResource DataValidationErrorsPointerOverBorderBrush}" />
</Style>
<Style Selector="^:pressed /template/ Border#Background">
<Setter Property="Border.Background" Value="{DynamicResource DataValidationErrorsPressedBackground}" />
<Setter Property="Border.BorderBrush" Value="{DynamicResource DataValidationErrorsPressedBorderBrush}" />
</Style>
<Style Selector="^:focus /template/ Border#Background">
<Setter Property="Border.Background" Value="{DynamicResource DataValidationErrorsSelectedBackground}" />
<Setter Property="Border.BorderBrush" Value="{DynamicResource DataValidationErrorsSelectedBorderBrush}" />
</Style>
</Style>
</Style> </Style>
</ControlTheme> </ControlTheme>
</ResourceDictionary> </ResourceDictionary>