feat: DatePicker&TimePicker validations.

This commit is contained in:
Zhang Dian 2023-05-08 10:19:58 +08:00
parent cece722496
commit e8ef024d59
3 changed files with 199 additions and 174 deletions

View File

@ -135,90 +135,93 @@
<Setter Property="VerticalAlignment" Value="Center" /> <Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate TargetType="DatePicker"> <ControlTemplate TargetType="DatePicker">
<Grid Name="LayoutRoot" Margin="{TemplateBinding Padding}"> <DataValidationErrors>
<Button <Grid Name="LayoutRoot" Margin="{TemplateBinding Padding}">
Name="PART_FlyoutButton" <Button
Width="298" Name="PART_FlyoutButton"
MinWidth="298" Width="298"
HorizontalAlignment="Stretch" MinWidth="298"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
Background="{TemplateBinding Background}" VerticalAlignment="Stretch"
BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}"
BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}"
CornerRadius="{TemplateBinding CornerRadius}" BorderThickness="{TemplateBinding BorderThickness}"
Cursor="Hand" CornerRadius="{TemplateBinding CornerRadius}"
Foreground="{TemplateBinding Foreground}" Cursor="Hand"
IsEnabled="{TemplateBinding IsEnabled}" DataValidationErrors.Errors="{TemplateBinding (DataValidationErrors.Errors)}"
Theme="{StaticResource DateTimePickerFlyoutButton}"> Foreground="{TemplateBinding Foreground}"
<Grid ColumnDefinitions="*, Auto"> IsEnabled="{TemplateBinding IsEnabled}"
<Grid Theme="{StaticResource DateTimePickerFlyoutButton}">
Name="PART_ButtonContentGrid" <Grid ColumnDefinitions="*, Auto">
Grid.Column="0" <Grid
VerticalAlignment="Center" Name="PART_ButtonContentGrid"
ColumnDefinitions="78*,Auto,132*,Auto,78*"> Grid.Column="0"
<TextBlock
Name="PART_DayTextBlock"
Padding="12,4"
HorizontalAlignment="Center"
VerticalAlignment="Center" VerticalAlignment="Center"
FontFamily="{TemplateBinding FontFamily}" ColumnDefinitions="78*,Auto,132*,Auto,78*">
FontSize="{TemplateBinding FontSize}" <TextBlock
FontWeight="{TemplateBinding FontWeight}" Name="PART_DayTextBlock"
Text="day" /> Padding="12,4"
<TextBlock HorizontalAlignment="Center"
Name="PART_MonthTextBlock" VerticalAlignment="Center"
Padding="12,4" FontFamily="{TemplateBinding FontFamily}"
VerticalAlignment="Center" FontSize="{TemplateBinding FontSize}"
FontFamily="{TemplateBinding FontFamily}" FontWeight="{TemplateBinding FontWeight}"
FontSize="{TemplateBinding FontSize}" Text="day" />
FontWeight="{TemplateBinding FontWeight}" <TextBlock
Text="month" Name="PART_MonthTextBlock"
TextAlignment="Left" /> Padding="12,4"
<TextBlock VerticalAlignment="Center"
Name="PART_YearTextBlock" FontFamily="{TemplateBinding FontFamily}"
Padding="12,4" FontSize="{TemplateBinding FontSize}"
HorizontalAlignment="Center" FontWeight="{TemplateBinding FontWeight}"
VerticalAlignment="Center" Text="month"
FontFamily="{TemplateBinding FontFamily}" TextAlignment="Left" />
FontSize="{TemplateBinding FontSize}" <TextBlock
FontWeight="{TemplateBinding FontWeight}" Name="PART_YearTextBlock"
Text="year" /> Padding="12,4"
<Rectangle HorizontalAlignment="Center"
x:Name="PART_FirstSpacer" VerticalAlignment="Center"
FontFamily="{TemplateBinding FontFamily}"
FontSize="{TemplateBinding FontSize}"
FontWeight="{TemplateBinding FontWeight}"
Text="year" />
<Rectangle
x:Name="PART_FirstSpacer"
Grid.Column="1"
Width="1"
Margin="0,4"
HorizontalAlignment="Center"
Fill="{DynamicResource DateTimePickerSeparatorBackground}" />
<Rectangle
x:Name="PART_SecondSpacer"
Grid.Column="3"
Width="1"
Margin="0,4"
HorizontalAlignment="Center"
Fill="{DynamicResource DateTimePickerSeparatorBackground}" />
</Grid>
<PathIcon
Name="PART_Icon"
Grid.Column="1" Grid.Column="1"
Width="1" Width="16"
Margin="0,4" Height="16"
HorizontalAlignment="Center" Margin="0,0,8,0"
Fill="{DynamicResource DateTimePickerSeparatorBackground}" /> Data="{DynamicResource DatePickerIconGlyph}"
<Rectangle Foreground="{DynamicResource DateTimePickerIconForeground}" />
x:Name="PART_SecondSpacer"
Grid.Column="3"
Width="1"
Margin="0,4"
HorizontalAlignment="Center"
Fill="{DynamicResource DateTimePickerSeparatorBackground}" />
</Grid> </Grid>
<PathIcon </Button>
Name="PART_Icon"
Grid.Column="1"
Width="16"
Height="16"
Margin="0,0,8,0"
Data="{DynamicResource DatePickerIconGlyph}"
Foreground="{DynamicResource DateTimePickerIconForeground}" />
</Grid>
</Button>
<Popup <Popup
Name="PART_Popup" Name="PART_Popup"
IsLightDismissEnabled="True" IsLightDismissEnabled="True"
Placement="Bottom" Placement="Bottom"
PlacementTarget="{TemplateBinding}" PlacementTarget="{TemplateBinding}"
WindowManagerAddShadowHint="False"> WindowManagerAddShadowHint="False">
<DatePickerPresenter Name="PART_PickerPresenter" /> <DatePickerPresenter Name="PART_PickerPresenter" />
</Popup> </Popup>
</Grid> </Grid>
</DataValidationErrors>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>

View File

@ -30,6 +30,25 @@
<Setter Property="BorderBrush" Value="{DynamicResource DateTimePickerButtonDisabledBorderBrush}" /> <Setter Property="BorderBrush" Value="{DynamicResource DateTimePickerButtonDisabledBorderBrush}" />
<Setter Property="Background" Value="{DynamicResource DateTimePickerButtonDisabledBackground}" /> <Setter Property="Background" Value="{DynamicResource DateTimePickerButtonDisabledBackground}" />
</Style> </Style>
<Style Selector="^:error">
<Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="{DynamicResource DataValidationErrorsBackground}" />
<Setter Property="BorderBrush" Value="Transparent" />
</Style>
<Style Selector="^:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="{DynamicResource DataValidationErrorsPointerOverBackground}" />
<Setter Property="BorderBrush" Value="Transparent" />
</Style>
<Style Selector="^:pressed /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="{DynamicResource DataValidationErrorsPressedBackground}" />
<Setter Property="BorderBrush" Value="Transparent" />
</Style>
<Style Selector="^:focus /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="{DynamicResource DataValidationErrorsSelectedBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource DataValidationErrorsSelectedBorderBrush}" />
</Style>
</Style>
</ControlTheme> </ControlTheme>
<!-- Theme for the items displayed in the selectors --> <!-- Theme for the items displayed in the selectors -->

View File

@ -139,106 +139,109 @@
<Setter Property="VerticalAlignment" Value="Center" /> <Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<Grid Name="LayoutRoot" Margin="{TemplateBinding Padding}"> <DataValidationErrors>
<Button <Grid Name="LayoutRoot" Margin="{TemplateBinding Padding}">
x:Name="PART_FlyoutButton" <Button
Width="242" x:Name="PART_FlyoutButton"
MinWidth="242" Width="242"
HorizontalAlignment="Stretch" MinWidth="242"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
Background="{TemplateBinding Background}" VerticalAlignment="Stretch"
BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}"
BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}"
CornerRadius="{TemplateBinding CornerRadius}" BorderThickness="{TemplateBinding BorderThickness}"
Cursor="Hand" CornerRadius="{TemplateBinding CornerRadius}"
Foreground="{TemplateBinding Foreground}" Cursor="Hand"
IsEnabled="{TemplateBinding IsEnabled}" DataValidationErrors.Errors="{TemplateBinding (DataValidationErrors.Errors)}"
Theme="{StaticResource DateTimePickerFlyoutButton}"> Foreground="{TemplateBinding Foreground}"
<Grid ColumnDefinitions="*, Auto"> IsEnabled="{TemplateBinding IsEnabled}"
<Grid Name="PART_FlyoutButtonContentGrid" Grid.Column="0"> Theme="{StaticResource DateTimePickerFlyoutButton}">
<!-- Ignore col defs here, set in code --> <Grid ColumnDefinitions="*, Auto">
<Border <Grid Name="PART_FlyoutButtonContentGrid" Grid.Column="0">
x:Name="PART_FirstPickerHost" <!-- Ignore col defs here, set in code -->
Grid.Column="0" <Border
HorizontalAlignment="Stretch" x:Name="PART_FirstPickerHost"
VerticalAlignment="Stretch"> Grid.Column="0"
<TextBlock HorizontalAlignment="Stretch"
x:Name="PART_HourTextBlock" VerticalAlignment="Stretch">
Padding="12,4" <TextBlock
HorizontalAlignment="Center" x:Name="PART_HourTextBlock"
VerticalAlignment="Center" Padding="12,4"
FontFamily="{TemplateBinding FontFamily}" HorizontalAlignment="Center"
FontSize="{TemplateBinding FontSize}" VerticalAlignment="Center"
FontWeight="{TemplateBinding FontWeight}" /> FontFamily="{TemplateBinding FontFamily}"
</Border> FontSize="{TemplateBinding FontSize}"
FontWeight="{TemplateBinding FontWeight}" />
</Border>
<Rectangle <Rectangle
Name="PART_FirstColumnDivider" Name="PART_FirstColumnDivider"
Grid.Column="1"
Width="1"
Margin="0,4"
HorizontalAlignment="Center"
Fill="{DynamicResource DateTimePickerSeparatorBackground}" />
<Border
x:Name="PART_SecondPickerHost"
Grid.Column="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<TextBlock
x:Name="PART_MinuteTextBlock"
Padding="12,4"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontFamily="{TemplateBinding FontFamily}"
FontSize="{TemplateBinding FontSize}"
FontWeight="{TemplateBinding FontWeight}" />
</Border>
<Rectangle
Name="PART_SecondColumnDivider"
Grid.Column="3"
Width="1"
Margin="0,4"
HorizontalAlignment="Center"
Fill="{DynamicResource DateTimePickerSeparatorBackground}" />
<Border
x:Name="PART_ThirdPickerHost"
Grid.Column="4"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<TextBlock
x:Name="PART_PeriodTextBlock"
Padding="12,4"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontFamily="{TemplateBinding FontFamily}"
FontSize="{TemplateBinding FontSize}"
FontWeight="{TemplateBinding FontWeight}" />
</Border>
</Grid>
<PathIcon
Name="PART_Icon"
Grid.Column="1" Grid.Column="1"
Width="1" Width="16"
Margin="0,4" Height="16"
HorizontalAlignment="Center" Margin="0,0,8,0"
Fill="{DynamicResource DateTimePickerSeparatorBackground}" /> Data="{DynamicResource TimePickerIconGlyph}"
Foreground="{DynamicResource DateTimePickerIconForeground}" />
<Border
x:Name="PART_SecondPickerHost"
Grid.Column="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<TextBlock
x:Name="PART_MinuteTextBlock"
Padding="12,4"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontFamily="{TemplateBinding FontFamily}"
FontSize="{TemplateBinding FontSize}"
FontWeight="{TemplateBinding FontWeight}" />
</Border>
<Rectangle
Name="PART_SecondColumnDivider"
Grid.Column="3"
Width="1"
Margin="0,4"
HorizontalAlignment="Center"
Fill="{DynamicResource DateTimePickerSeparatorBackground}" />
<Border
x:Name="PART_ThirdPickerHost"
Grid.Column="4"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<TextBlock
x:Name="PART_PeriodTextBlock"
Padding="12,4"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontFamily="{TemplateBinding FontFamily}"
FontSize="{TemplateBinding FontSize}"
FontWeight="{TemplateBinding FontWeight}" />
</Border>
</Grid> </Grid>
<PathIcon
Name="PART_Icon"
Grid.Column="1"
Width="16"
Height="16"
Margin="0,0,8,0"
Data="{DynamicResource TimePickerIconGlyph}"
Foreground="{DynamicResource DateTimePickerIconForeground}" />
</Grid>
</Button> </Button>
<Popup <Popup
Name="PART_Popup" Name="PART_Popup"
IsLightDismissEnabled="True" IsLightDismissEnabled="True"
Placement="Bottom" Placement="Bottom"
PlacementTarget="{TemplateBinding}" PlacementTarget="{TemplateBinding}"
WindowManagerAddShadowHint="False"> WindowManagerAddShadowHint="False">
<TimePickerPresenter Name="PART_PickerPresenter" /> <TimePickerPresenter Name="PART_PickerPresenter" />
</Popup> </Popup>
</Grid> </Grid>
</DataValidationErrors>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>