fix: ClearButton will take the icon place when TextBox has value.

(cherry picked from commit 7a6c42e1066606daecc6448bfcc01ef8baf9072f)
This commit is contained in:
Zhang Dian 2024-08-10 13:50:33 +08:00
parent 871f112800
commit 2fadfdd5de
2 changed files with 126 additions and 108 deletions

View File

@ -27,15 +27,14 @@
Background="{TemplateBinding Background}" Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}"> CornerRadius="{TemplateBinding CornerRadius}"/>
<Grid <Grid
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
VerticalAlignment="Center" VerticalAlignment="Stretch"
ColumnDefinitions="*, Auto, Auto"> ColumnDefinitions="*, Auto">
<TextBox <TextBox
Name="PART_TextBox" Name="PART_TextBox"
Grid.Column="0" Grid.Column="0"
Grid.ColumnSpan="2"
MinHeight="{DynamicResource CalendarDatePickerDefaultHeight}" MinHeight="{DynamicResource CalendarDatePickerDefaultHeight}"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
VerticalAlignment="Center" VerticalAlignment="Center"
@ -82,7 +81,7 @@
Theme="{DynamicResource InnerIconButton}" /> Theme="{DynamicResource InnerIconButton}" />
<Button <Button
Name="PART_Button" Name="PART_Button"
Grid.Column="2" Grid.Column="1"
Padding="0,0,8,0" Padding="0,0,8,0"
Content="{DynamicResource CalendarDatePickerIconGlyph}" Content="{DynamicResource CalendarDatePickerIconGlyph}"
Focusable="False" Focusable="False"
@ -113,7 +112,6 @@
</Border> </Border>
</Popup> </Popup>
</Grid> </Grid>
</Border>
</Panel> </Panel>
</DataValidationErrors> </DataValidationErrors>
@ -123,20 +121,19 @@
<Style Selector="^.clearButton, ^.ClearButton"> <Style Selector="^.clearButton, ^.ClearButton">
<Style Selector="^:pointerover /template/ Button#ClearButton"> <Style Selector="^:pointerover /template/ Button#ClearButton">
<Setter Property="IsVisible" Value="{Binding $parent[CalendarDatePicker].SelectedDate, Converter={x:Static ObjectConverters.IsNotNull}}"></Setter> <Setter Property="IsVisible" Value="{Binding $parent[CalendarDatePicker].SelectedDate, Converter={x:Static ObjectConverters.IsNotNull}}" />
</Style>
<Style Selector="^:pointerover /template/ Button#PART_Button">
<Setter Property="IsVisible" Value="{Binding $parent[CalendarDatePicker].SelectedDate, Converter={x:Static ObjectConverters.IsNull}}" />
</Style> </Style>
</Style> </Style>
<Style Selector="^.Large"> <Style Selector="^.Large /template/ TextBox#PART_TextBox">
<Style Selector="^ /template/ TextBox#PART_TextBox">
<Setter Property="MinHeight" Value="{DynamicResource CalendarDatePickerInnerLargeHeight}" /> <Setter Property="MinHeight" Value="{DynamicResource CalendarDatePickerInnerLargeHeight}" />
</Style> </Style>
</Style> <Style Selector="^.Small /template/ TextBox#PART_TextBox">
<Style Selector="^.Small">
<Style Selector="^ /template/ TextBox#PART_TextBox">
<Setter Property="MinHeight" Value="{DynamicResource CalendarDatePickerInnerSmallHeight}" /> <Setter Property="MinHeight" Value="{DynamicResource CalendarDatePickerInnerSmallHeight}" />
</Style> </Style>
</Style>
<Style Selector="^:pointerover"> <Style Selector="^:pointerover">
<Style Selector="^ /template/ Border#Background"> <Style Selector="^ /template/ Border#Background">

View File

@ -41,20 +41,20 @@
<Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Left" /> <Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Top" /> <Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="MinHeight" Value="{DynamicResource ComboBoxDefaultHeight}" />
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate TargetType="ComboBox"> <ControlTemplate TargetType="ComboBox">
<DataValidationErrors> <DataValidationErrors>
<Grid ColumnDefinitions="*, Auto, 32"> <Grid ColumnDefinitions="*, Auto">
<Border <Border
x:Name="Background" x:Name="Background"
Grid.Column="0" Grid.Column="0"
Grid.ColumnSpan="3" Grid.ColumnSpan="2"
MinWidth="{DynamicResource ComboBoxThemeMinWidth}"
MinHeight="{DynamicResource ComboBoxDefaultHeight}"
Background="{TemplateBinding Background}" Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}" /> CornerRadius="{TemplateBinding CornerRadius}"
MinHeight="{TemplateBinding MinHeight}" />
<TextBlock <TextBlock
x:Name="PlaceholderTextBlock" x:Name="PlaceholderTextBlock"
Grid.Column="0" Grid.Column="0"
@ -78,13 +78,15 @@
<Button <Button
Name="ClearButton" Name="ClearButton"
Grid.Column="1" Grid.Column="1"
Margin="0,0,8,0"
Command="{Binding $parent[ComboBox].Clear}" Command="{Binding $parent[ComboBox].Clear}"
Content="{DynamicResource IconButtonClearData}" Content="{DynamicResource IconButtonClearData}"
Focusable="False"
IsVisible="False" IsVisible="False"
Theme="{DynamicResource InnerIconButton}" /> Theme="{DynamicResource InnerIconButton}" />
<Border <Border
x:Name="DropDownOverlay" x:Name="DropDownOverlay"
Grid.Column="2" Grid.Column="1"
Width="30" Width="30"
Margin="0,1,1,1" Margin="0,1,1,1"
HorizontalAlignment="Right" HorizontalAlignment="Right"
@ -93,12 +95,10 @@
<PathIcon <PathIcon
x:Name="DropDownGlyph" x:Name="DropDownGlyph"
Grid.Column="2" Grid.Column="1"
Width="12" Width="12"
Height="12" Height="12"
Margin="0,0,10,0" Margin="0,0,12,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Data="{DynamicResource ComboBoxIcon}" Data="{DynamicResource ComboBoxIcon}"
Foreground="{DynamicResource ComboBoxIconDefaultForeground}" Foreground="{DynamicResource ComboBoxIconDefaultForeground}"
IsHitTestVisible="False" IsHitTestVisible="False"
@ -146,12 +146,15 @@
<Style Selector="^:pointerover /template/ Button#ClearButton"> <Style Selector="^:pointerover /template/ Button#ClearButton">
<Setter Property="IsVisible" Value="{Binding $parent[ComboBox].SelectionBoxItem, Converter={x:Static ObjectConverters.IsNotNull}}" /> <Setter Property="IsVisible" Value="{Binding $parent[ComboBox].SelectionBoxItem, Converter={x:Static ObjectConverters.IsNotNull}}" />
</Style> </Style>
<Style Selector="^:pointerover /template/ PathIcon#DropDownGlyph">
<Setter Property="IsVisible" Value="{Binding $parent[ComboBox].SelectionBoxItem, Converter={x:Static ObjectConverters.IsNull}}"/>
</Style>
</Style> </Style>
<Style Selector="^.Large /template/ Border#Background"> <Style Selector="^.Large">
<Setter Property="MinHeight" Value="{DynamicResource ComboBoxLargeHeight}" /> <Setter Property="MinHeight" Value="{DynamicResource ComboBoxLargeHeight}" />
</Style> </Style>
<Style Selector="^.Small /template/ Border#Background"> <Style Selector="^.Small">
<Setter Property="MinHeight" Value="{DynamicResource ComboBoxSmallHeight}" /> <Setter Property="MinHeight" Value="{DynamicResource ComboBoxSmallHeight}" />
</Style> </Style>
@ -159,10 +162,19 @@
<Style Selector="^:pointerover"> <Style Selector="^:pointerover">
<Setter Property="Background" Value="{DynamicResource ComboBoxSelectorPointeroverBackground}" /> <Setter Property="Background" Value="{DynamicResource ComboBoxSelectorPointeroverBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource ComboBoxSelectorPointeroverBorderBrush}" /> <Setter Property="BorderBrush" Value="{DynamicResource ComboBoxSelectorPointeroverBorderBrush}" />
</Style> <Style Selector="^ /template/ PathIcon#DropDownGlyph">
<Style Selector="^:pointerover /template/ PathIcon#DropDownGlyph">
<Setter Property="Foreground" Value="{DynamicResource ComboBoxIconPointeroverForeground}" /> <Setter Property="Foreground" Value="{DynamicResource ComboBoxIconPointeroverForeground}" />
</Style> </Style>
</Style>
<!-- Focus State -->
<Style Selector="^:focus">
<Setter Property="Background" Value="{DynamicResource ComboBoxSelectorFocusBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource ComboBoxSelectorFocusBorderBrush}" />
<Style Selector="^ /template/ PathIcon#DropDownGlyph">
<Setter Property="Foreground" Value="{DynamicResource ComboBoxIconFocusForeground}" />
</Style>
</Style>
<!-- Pressed State --> <!-- Pressed State -->
<Style Selector="^:pressed"> <Style Selector="^:pressed">
@ -222,6 +234,10 @@
<Setter Property="Background" Value="{DynamicResource ComboBoxSelectorBorderedPressedBackground}" /> <Setter Property="Background" Value="{DynamicResource ComboBoxSelectorBorderedPressedBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource ComboBoxSelectorBorderedPressedBorderBrush}" /> <Setter Property="BorderBrush" Value="{DynamicResource ComboBoxSelectorBorderedPressedBorderBrush}" />
</Style> </Style>
<Style Selector="^:focus /template/ Border#Background">
<Setter Property="Background" Value="{DynamicResource ComboBoxSelectorBorderedFocusBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource ComboBoxSelectorBorderedFocusBorderBrush}" />
</Style>
<Style Selector="^:disabled"> <Style Selector="^:disabled">
<Style Selector="^ /template/ Border#Background"> <Style Selector="^ /template/ Border#Background">
<Setter Property="Background" Value="{DynamicResource ComboBoxSelectorDisabledBackground}" /> <Setter Property="Background" Value="{DynamicResource ComboBoxSelectorDisabledBackground}" />
@ -284,6 +300,10 @@
<Setter Property="Background" Value="{DynamicResource ComboBoxItemPointeroverBackground}" /> <Setter Property="Background" Value="{DynamicResource ComboBoxItemPointeroverBackground}" />
</Style> </Style>
<Style Selector="^:focus /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="{DynamicResource ComboBoxItemFocusBackground}" />
</Style>
<Style Selector="^:disabled /template/ ContentPresenter#PART_ContentPresenter"> <Style Selector="^:disabled /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="{DynamicResource ComboBoxItemDisabledBackground}" /> <Setter Property="Background" Value="{DynamicResource ComboBoxItemDisabledBackground}" />
</Style> </Style>
@ -303,5 +323,6 @@
<Setter Property="Background" Value="{DynamicResource ComboBoxItemSelectedPointeroverBackground}" /> <Setter Property="Background" Value="{DynamicResource ComboBoxItemSelectedPointeroverBackground}" />
</Style> </Style>
</Style> </Style>
</ControlTheme> </ControlTheme>
</ResourceDictionary> </ResourceDictionary>