From 638894dba8cdb2c73f22614e25d29094c27bbef5 Mon Sep 17 00:00:00 2001 From: Kevin Bost Date: Thu, 28 May 2026 23:26:01 -0700 Subject: [PATCH 1/2] feat(ComboBox): Add dedicated dropdown background brush Introduces `MaterialDesign.Brush.ComboBox.DropDown.Background` to provide specific theming for the ComboBox and DataGridComboBox dropdown. This change moves away from relying on the general `MaterialDesign.Brush.Background` or a complex binding setup, allowing for consistent and explicit control over the dropdown's visual style. It also removes the `RemoveAlphaBrushConverter` usage for applying the background. Fixes #3887. --- .../Themes/MaterialDesignTheme.ComboBox.xaml | 8 ++--- .../Themes/MaterialDesignTheme.Dark.xaml | 1 + ...MaterialDesignTheme.DataGrid.ComboBox.xaml | 8 ++--- .../Themes/MaterialDesignTheme.Light.xaml | 1 + .../ThemeColors.json | 9 +++++ .../WPF/ComboBoxes/ComboBoxTests.cs | 36 +++++++++++++++++++ .../WPF/Theme/ThemeTests.g.cs | 7 ++++ 7 files changed, 62 insertions(+), 8 deletions(-) diff --git a/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ComboBox.xaml b/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ComboBox.xaml index eb43db54f6..5746b3ddd4 100644 --- a/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ComboBox.xaml +++ b/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ComboBox.xaml @@ -534,7 +534,7 @@ PopupAnimation="Fade" RelativeHorizontalOffset="-6" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" - Tag="{DynamicResource MaterialDesign.Brush.Background}" + Tag="{DynamicResource MaterialDesign.Brush.ComboBox.DropDown.Background}" UpVerticalOffset="15" UseLayoutRounding="{TemplateBinding UseLayoutRounding}" VerticalOffset="0"> @@ -557,7 +557,7 @@ + Background="Transparent"> @@ -796,8 +796,8 @@ - - + + diff --git a/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Dark.xaml b/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Dark.xaml index c0f104b5c7..ddc770bd20 100644 --- a/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Dark.xaml +++ b/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Dark.xaml @@ -28,6 +28,7 @@ + diff --git a/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DataGrid.ComboBox.xaml b/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DataGrid.ComboBox.xaml index 49840244c0..45e5533fe3 100644 --- a/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DataGrid.ComboBox.xaml +++ b/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DataGrid.ComboBox.xaml @@ -159,7 +159,7 @@ @@ -167,7 +167,7 @@ @@ -285,7 +285,7 @@ @@ -293,7 +293,7 @@ diff --git a/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Light.xaml b/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Light.xaml index 68dac171db..8f00d024f1 100644 --- a/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Light.xaml +++ b/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Light.xaml @@ -28,6 +28,7 @@ + diff --git a/src/MaterialDesignToolkit.ResourceGeneration/ThemeColors.json b/src/MaterialDesignToolkit.ResourceGeneration/ThemeColors.json index 9f8172bd23..f3db724322 100644 --- a/src/MaterialDesignToolkit.ResourceGeneration/ThemeColors.json +++ b/src/MaterialDesignToolkit.ResourceGeneration/ThemeColors.json @@ -246,6 +246,15 @@ }, "alternateKeys": [] }, + { + "name": "MaterialDesign.Brush.ComboBox.DropDown.Background", + "themeValues": { + "light": "Neutral900", + "dark": "Neutral100" + }, + "alternateKeys": [], + "obsoleteKeys": [] + }, { "name": "MaterialDesign.Brush.ComboBox.Popup.DarkBackground", "themeValues": { diff --git a/tests/MaterialDesignThemes.UITests/WPF/ComboBoxes/ComboBoxTests.cs b/tests/MaterialDesignThemes.UITests/WPF/ComboBoxes/ComboBoxTests.cs index e8e423c231..67ecc714ed 100644 --- a/tests/MaterialDesignThemes.UITests/WPF/ComboBoxes/ComboBoxTests.cs +++ b/tests/MaterialDesignThemes.UITests/WPF/ComboBoxes/ComboBoxTests.cs @@ -1,4 +1,5 @@ using System.ComponentModel; +using System.Windows.Media; using MaterialDesignThemes.UITests.WPF.TextBoxes; namespace MaterialDesignThemes.UITests.WPF.ComboBoxes; @@ -269,4 +270,39 @@ public async Task ComboBox_BorderShouldDependOnAppliedStyle(string style, double Thickness thickness = await border.GetBorderThickness(); await Assert.That(thickness).IsEqualTo(new Thickness(left, top, right, bottom)); } + + [Test] + [Description("Issue 3887")] + public async Task ComboBox_UsesDropDownBackgroundResource_WhenBackgroundIsNotSet() + { + await using var recorder = new TestRecorder(App); + + var stackPanel = await LoadXaml($$""" + + + + + + + + + + + """); + + var comboBox = await stackPanel.GetElement("Combo"); + await comboBox.LeftClick(Position.RightCenter); + + var popup = await Wait.For(async () => await comboBox.GetElement("PART_Popup")); + var popupBackground = await popup.GetProperty(Control.BackgroundProperty); + var popupBackgroundBrush = popupBackground as SolidColorBrush; + + await Assert.That(popupBackground).IsNotNull(); + await Assert.That(popupBackgroundBrush).IsNotNull(); + await Assert.That(popupBackgroundBrush!.Color).IsEqualTo((Color)ColorConverter.ConvertFromString("#CC336699")); + + recorder.Success(); + } } diff --git a/tests/MaterialDesignThemes.UITests/WPF/Theme/ThemeTests.g.cs b/tests/MaterialDesignThemes.UITests/WPF/Theme/ThemeTests.g.cs index b7063d9a20..498b8ffff3 100644 --- a/tests/MaterialDesignThemes.UITests/WPF/Theme/ThemeTests.g.cs +++ b/tests/MaterialDesignThemes.UITests/WPF/Theme/ThemeTests.g.cs @@ -53,6 +53,7 @@ private partial string GetXamlWrapPanel() + @@ -345,6 +346,11 @@ private partial async Task AssertAllThemeBrushesSet(IVisualElement pa Color? textBlockBackground = await textBlock.GetBackgroundColor(); await Assert.That(textBlockBackground).IsEqualTo(await GetResourceColor("MaterialDesign.Brush.ComboBox.OutlineBorder")); } + { + IVisualElement textBlock = await panel.GetElement("[Text=\"ComboBox.DropDown.Background\"]"); + Color? textBlockBackground = await textBlock.GetBackgroundColor(); + await Assert.That(textBlockBackground).IsEqualTo(await GetResourceColor("MaterialDesign.Brush.ComboBox.DropDown.Background")); + } { IVisualElement textBlock = await panel.GetElement("[Text=\"ComboBox.Popup.DarkBackground\"]"); Color? textBlockBackground = await textBlock.GetBackgroundColor(); @@ -955,6 +961,7 @@ private static IEnumerable GetBrushResourceNames() yield return "MaterialDesign.Brush.ComboBox.HoverBorder"; yield return "MaterialDesign.Brush.ComboBox.Border"; yield return "MaterialDesign.Brush.ComboBox.OutlineBorder"; + yield return "MaterialDesign.Brush.ComboBox.DropDown.Background"; yield return "MaterialDesign.Brush.ComboBox.Popup.DarkBackground"; yield return "MaterialDesign.Brush.ComboBox.Popup.DarkForeground"; yield return "MaterialDesign.Brush.ComboBox.Popup.LightBackground"; From ea0640be81b1b806915ad2c3429d77e4c51d4def Mon Sep 17 00:00:00 2001 From: Kevin Bost Date: Thu, 28 May 2026 23:40:07 -0700 Subject: [PATCH 2/2] test(ComboBox): Simplify popup background color assertion Refactors the ComboBox popup background UI test to use a direct helper for retrieving the color value. This eliminates the need for manual casting and null checks on the brush type, making the assertion more concise. --- .../WPF/ComboBoxes/ComboBoxTests.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/MaterialDesignThemes.UITests/WPF/ComboBoxes/ComboBoxTests.cs b/tests/MaterialDesignThemes.UITests/WPF/ComboBoxes/ComboBoxTests.cs index 67ecc714ed..d74644be00 100644 --- a/tests/MaterialDesignThemes.UITests/WPF/ComboBoxes/ComboBoxTests.cs +++ b/tests/MaterialDesignThemes.UITests/WPF/ComboBoxes/ComboBoxTests.cs @@ -279,11 +279,10 @@ public async Task ComboBox_UsesDropDownBackgroundResource_WhenBackgroundIsNotSet var stackPanel = await LoadXaml($$""" - + + Color="#CC336699" /> @@ -292,16 +291,14 @@ public async Task ComboBox_UsesDropDownBackgroundResource_WhenBackgroundIsNotSet """); - var comboBox = await stackPanel.GetElement("Combo"); + var comboBox = await stackPanel.GetElement(); await comboBox.LeftClick(Position.RightCenter); var popup = await Wait.For(async () => await comboBox.GetElement("PART_Popup")); - var popupBackground = await popup.GetProperty(Control.BackgroundProperty); - var popupBackgroundBrush = popupBackground as SolidColorBrush; + Color? popupBackground = await popup.GetBackgroundColor(); await Assert.That(popupBackground).IsNotNull(); - await Assert.That(popupBackgroundBrush).IsNotNull(); - await Assert.That(popupBackgroundBrush!.Color).IsEqualTo((Color)ColorConverter.ConvertFromString("#CC336699")); + await Assert.That(popupBackground).IsEqualTo((Color)ColorConverter.ConvertFromString("#CC336699")); recorder.Success(); }