Skip to content

Commit 69c29d1

Browse files
Ensure clear button does not overlap editable text in ComboBox (#3279)
* Ensure clear button does not overlap editable text in ComboBox * Added comment on the initial offset
1 parent 06f781a commit 69c29d1

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

MaterialDesignThemes.Wpf/Converters/DoubleToThicknessConverter.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ namespace MaterialDesignThemes.Wpf.Converters
55
{
66
internal class DoubleToThicknessConverter : IValueConverter
77
{
8+
public double InitialOffset { get; set; }
9+
810
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
911
=> (Dock)parameter switch
1012
{
11-
Dock.Left => new Thickness((double)value, 0, 0, 0),
12-
Dock.Top => new Thickness(0, (double)value, 0, 0),
13-
Dock.Right => new Thickness(0, 0, (double)value, 0),
14-
Dock.Bottom => new Thickness(0, 0, 0, (double)value),
13+
Dock.Left => new Thickness(InitialOffset + (double)value, 0, 0, 0),
14+
Dock.Top => new Thickness(0, InitialOffset + (double)value, 0, 0),
15+
Dock.Right => new Thickness(0, 0, InitialOffset + (double)value, 0),
16+
Dock.Bottom => new Thickness(0, 0, 0, InitialOffset + (double)value),
1517
_ => Binding.DoNothing
1618
};
1719

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ComboBox.xaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
<converters:FloatingHintOffsetCalculationConverter x:Key="FloatingHintOffsetCalculationConverter" />
2727
<converters:ComboBoxClearButtonMarginConverter x:Key="ComboBoxClearButtonMarginConverter" />
2828
<converters:DoubleToThicknessConverter x:Key="DoubleToThicknessConverter" />
29+
<!-- The InitialOffset of -8 is to adjust for internal margin/padding between the "selected content (text)" and the combo box chevron arrow -->
30+
<converters:DoubleToThicknessConverter x:Key="DoubleToThicknessConverterWithNegativeOffset" InitialOffset="-8" />
2931
<converters:ThicknessCloneConverter x:Key="HelperTextMarginConverter" CloneEdges="Left" />
3032
<converters:ThicknessCloneConverter x:Key="DefaultOrFilledStyleTrailingIconPaddingConverterTop"
3133
AdditionalOffsetTop="2"
@@ -848,6 +850,11 @@
848850
<Setter TargetName="PART_Popup" Property="Background" Value="{Binding Tag, RelativeSource={RelativeSource Self}, Converter={StaticResource RemoveAlphaBrushConverter}}" />
849851
<Setter TargetName="PART_Popup" Property="Tag" Value="{DynamicResource MaterialDesign.Brush.ComboBox.Popup.DarkBackground}" />
850852
</MultiTrigger>
853+
854+
<!-- PART_ClearButton -->
855+
<DataTrigger Binding="{Binding ElementName=PART_ClearButton, Path=IsVisible}" Value="True">
856+
<Setter TargetName="PART_EditableTextBox" Property="Margin" Value="{Binding ActualWidth, ElementName=PART_ClearButton, Converter={StaticResource DoubleToThicknessConverterWithNegativeOffset}, ConverterParameter={x:Static Dock.Right}}" />
857+
</DataTrigger>
851858
</ControlTemplate.Triggers>
852859
</ControlTemplate>
853860

0 commit comments

Comments
 (0)