feat: implement IsEditable for ComboBox.

This commit is contained in:
Zhang Dian
2025-10-04 11:11:07 +08:00
parent 47c6899b94
commit be2b25a94b
3 changed files with 67 additions and 38 deletions

View File

@@ -66,8 +66,14 @@
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
TextTrimming="CharacterEllipsis"
Foreground="{TemplateBinding PlaceholderForeground}"
IsVisible="{TemplateBinding SelectionBoxItem,Converter={x:Static ObjectConverters.IsNull}}"
Text="{TemplateBinding PlaceholderText}" />
Text="{TemplateBinding PlaceholderText}">
<TextBlock.IsVisible>
<MultiBinding Converter="{x:Static BoolConverters.And}">
<TemplateBinding Property="SelectionBoxItem" Converter="{x:Static ObjectConverters.IsNull}" />
<TemplateBinding Property="IsEditable" Converter="{x:Static BoolConverters.Not}" />
</MultiBinding>
</TextBlock.IsVisible>
</TextBlock>
<ContentPresenter
Name="ContentPresenter"
Grid.Column="0"
@@ -75,7 +81,20 @@
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" />
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
IsVisible="{TemplateBinding IsEditable, Converter={x:Static BoolConverters.Not}}" />
<TextBox
Name="PART_EditableTextBox"
Grid.Column="0"
Theme="{StaticResource LooklessTextBox}"
Padding="{TemplateBinding Padding}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
Foreground="{TemplateBinding Foreground}"
Text="{TemplateBinding Text, Mode=TwoWay}"
Watermark="{TemplateBinding PlaceholderText}"
IsVisible="{TemplateBinding IsEditable}" />
<Button
Name="ClearButton"
Grid.Column="1"
@@ -211,6 +230,11 @@
</Style>
</Style>
<Style Selector="^[IsEditable=true]">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="KeyboardNavigation.TabNavigation" Value="Local" />
</Style>
<Style Selector="^.Bordered">
<Style Selector="^ /template/ Border#Background">
<Setter Property="Background" Value="{DynamicResource ComboBoxSelectorBorderedBackground}" />

View File

@@ -491,6 +491,7 @@
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="FocusAdorner" Value="{x:Null}" />
<Setter Property="ScrollViewer.IsScrollChainingEnabled" Value="True" />
<Setter Property="ContextFlyout" Value="{StaticResource DefaultTextBoxContextFlyout}" />
<Setter Property="Template">
<ControlTemplate TargetType="TextBox">
<Border Name="PART_ContentPresenterBorder" MinHeight="{TemplateBinding MinHeight}">