Skip to content

Commit 32eb536

Browse files
Fix HorizontalContentAlignment on ComboBox (selected value) (#3458)
* Fix HorizontalContentAlignment on ComboBox (selected value) * Fix test to just check the alignment rather than measuring * Remove comments no longer needed --------- Co-authored-by: Kevin Bost <kitokeboo@gmail.com>
1 parent c338f12 commit 32eb536

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

MaterialDesignThemes.UITests/WPF/ComboBoxes/ComboBoxTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,29 @@ public async Task ComboBox_WithHintAndValidationError_RespectsPadding(string sty
257257

258258
recorder.Success();
259259
}
260+
261+
[Theory]
262+
[InlineData(HorizontalAlignment.Left)]
263+
[InlineData(HorizontalAlignment.Right)]
264+
[InlineData(HorizontalAlignment.Center)]
265+
[InlineData(HorizontalAlignment.Stretch)]
266+
[Description("Issue 3433")]
267+
public async Task ComboBox_WithHorizontalContentAlignment_RespectsAlignment(HorizontalAlignment alignment)
268+
{
269+
await using var recorder = new TestRecorder(App);
270+
271+
var stackPanel = await LoadXaml<StackPanel>($"""
272+
<StackPanel>
273+
<ComboBox HorizontalContentAlignment="{alignment}">
274+
<ComboBoxItem Content="TEST" IsSelected="True" />
275+
</ComboBox>
276+
</StackPanel>
277+
""");
278+
var comboBox = await stackPanel.GetElement<ComboBox>("/ComboBox");
279+
var selectedItemPresenter = await comboBox.GetElement<ContentPresenter>("contentPresenter");
280+
281+
Assert.Equal(alignment, await selectedItemPresenter.GetHorizontalAlignment());
282+
283+
recorder.Success();
284+
}
260285
}

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ComboBox.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@
363363
ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
364364
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
365365
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
366+
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
366367
IsHitTestVisible="False" />
367368
<TextBox x:Name="PART_EditableTextBox"
368369
Grid.Column="1"

0 commit comments

Comments
 (0)