feat: add clear button to TimePicker

This commit is contained in:
rabbitism 2023-10-04 14:56:04 +08:00
parent d638b0603d
commit 385e1e2cd5
3 changed files with 29 additions and 3 deletions

View File

@ -9,6 +9,7 @@
mc:Ignorable="d"> mc:Ignorable="d">
<StackPanel Spacing="20"> <StackPanel Spacing="20">
<TimePicker /> <TimePicker />
<TimePicker Classes="ClearButton" />
<TimePicker MinuteIncrement="15" /> <TimePicker MinuteIncrement="15" />
<TimePicker ClockIdentifier="24HourClock" /> <TimePicker ClockIdentifier="24HourClock" />
<TimePicker ClockIdentifier="12HourClock" IsEnabled="False" /> <TimePicker ClockIdentifier="12HourClock" IsEnabled="False" />

View File

@ -228,10 +228,10 @@
<Button <Button
Name="ClearButton" Name="ClearButton"
Grid.Column="1" Grid.Column="1"
Margin="0,0,8,0"
Command="{Binding $parent[DatePicker].Clear}" Command="{Binding $parent[DatePicker].Clear}"
Content="{DynamicResource TextBoxClearButtonData}" Content="{DynamicResource TextBoxClearButtonData}"
IsVisible="False" IsVisible="False"
Margin="0 0 8 0"
Theme="{DynamicResource ButtonInputInnerButton}" /> Theme="{DynamicResource ButtonInputInnerButton}" />
</Grid> </Grid>
</DataValidationErrors> </DataValidationErrors>

View File

@ -139,11 +139,17 @@
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<DataValidationErrors> <DataValidationErrors>
<Grid Name="LayoutRoot" Margin="{TemplateBinding Padding}"> <Grid
Name="LayoutRoot"
Margin="{TemplateBinding Padding}"
ColumnDefinitions="*, Auto">
<Button <Button
x:Name="PART_FlyoutButton" x:Name="PART_FlyoutButton"
Grid.Column="0"
Grid.ColumnSpan="2"
Width="242" Width="242"
MinWidth="242" MinWidth="242"
MinHeight="{DynamicResource DateTimePickerButtonDefaultHeight}"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" VerticalAlignment="Stretch"
Background="{TemplateBinding Background}" Background="{TemplateBinding Background}"
@ -154,7 +160,6 @@
DataValidationErrors.Errors="{TemplateBinding (DataValidationErrors.Errors)}" DataValidationErrors.Errors="{TemplateBinding (DataValidationErrors.Errors)}"
Foreground="{TemplateBinding Foreground}" Foreground="{TemplateBinding Foreground}"
IsEnabled="{TemplateBinding IsEnabled}" IsEnabled="{TemplateBinding IsEnabled}"
MinHeight="{DynamicResource DateTimePickerButtonDefaultHeight}"
Theme="{StaticResource DateTimePickerFlyoutButton}"> Theme="{StaticResource DateTimePickerFlyoutButton}">
<Grid ColumnDefinitions="*, Auto"> <Grid ColumnDefinitions="*, Auto">
<Grid Name="PART_FlyoutButtonContentGrid" Grid.Column="0"> <Grid Name="PART_FlyoutButtonContentGrid" Grid.Column="0">
@ -234,16 +239,36 @@
<Popup <Popup
Name="PART_Popup" Name="PART_Popup"
Grid.Column="0"
Grid.ColumnSpan="2"
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>
<Button
Name="ClearButton"
Grid.Column="1"
Margin="0,0,8,0"
Command="{Binding $parent[TimePicker].Clear}"
Content="{DynamicResource TextBoxClearButtonData}"
IsVisible="False"
Theme="{DynamicResource ButtonInputInnerButton}" />
</Grid> </Grid>
</DataValidationErrors> </DataValidationErrors>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
<Style Selector="^.clearButton:pointerover, ^.ClearButton:pointerover">
<Style Selector="^:not(:hasnotime) /template/ Button#ClearButton">
<Setter Property="IsVisible" Value="True" />
</Style>
<Style Selector="^:not(:hasnotime) /template/ PathIcon#PART_Icon">
<Setter Property="Opacity" Value="0" />
</Style>
</Style>
<Style Selector="^:disabled /template/ PathIcon#PART_Icon"> <Style Selector="^:disabled /template/ PathIcon#PART_Icon">
<Setter Property="Foreground" Value="{DynamicResource DateTimePickerButtonDisabledIconForeground}" /> <Setter Property="Foreground" Value="{DynamicResource DateTimePickerButtonDisabledIconForeground}" />