From c1755dfd1234f8da980810112712c4a9f3b292c7 Mon Sep 17 00:00:00 2001 From: Kevin Bost Date: Thu, 28 May 2026 23:26:01 -0700 Subject: [PATCH 1/4] 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 b6a0ffa282..daa81fe88c 100644 --- a/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Dark.xaml +++ b/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Dark.xaml @@ -29,6 +29,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 43d97f9d70..e972991495 100644 --- a/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Light.xaml +++ b/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Light.xaml @@ -29,6 +29,7 @@ + diff --git a/src/MaterialDesignToolkit.ResourceGeneration/ThemeColors.json b/src/MaterialDesignToolkit.ResourceGeneration/ThemeColors.json index a6dc8a280e..33e51770af 100644 --- a/src/MaterialDesignToolkit.ResourceGeneration/ThemeColors.json +++ b/src/MaterialDesignToolkit.ResourceGeneration/ThemeColors.json @@ -248,6 +248,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 bdb40a32f1..cc047b0b40 100644 --- a/tests/MaterialDesignThemes.UITests/WPF/Theme/ThemeTests.g.cs +++ b/tests/MaterialDesignThemes.UITests/WPF/Theme/ThemeTests.g.cs @@ -54,6 +54,7 @@ private partial string GetXamlWrapPanel() + @@ -352,6 +353,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(); @@ -968,6 +974,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 c018865f2ca387a82985da729d54a60bae9c33dd Mon Sep 17 00:00:00 2001 From: Kevin Bost Date: Thu, 28 May 2026 23:40:07 -0700 Subject: [PATCH 2/4] 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(); } From 50457b6f4fd6d441fad6e42497de455e432ccfe7 Mon Sep 17 00:00:00 2001 From: Kevin Bost Date: Thu, 11 Jun 2026 21:28:22 -0700 Subject: [PATCH 3/4] Update dependencies and refactor TUnit assertions Updates the .NET SDK and various NuGet packages, including TUnit, Microsoft.CodeAnalysis, and CommunityToolkit.Mvvm. Refactors test assertions to use native TUnit methods like IsTrue, IsFalse, and IsNull for better clarity, and removes custom assertion extensions that are no longer required. --- .editorconfig | 4 ++ Directory.packages.props | 36 +++++----- global.json | 2 +- .../MaterialDesignThemes.UITests.csproj | 1 - .../TUnit/IsCloseToExtensions.cs | 72 ------------------- .../MaterialDesignThemes.UITests/TestBase.cs | 1 + .../WPF/ComboBoxes/ComboBoxTests.cs | 5 +- .../WPF/TabControls/TabControlTests.cs | 4 +- .../ButtonProgressAssistTests.cs | 8 +-- .../DataGridAssistTests.cs | 10 +-- .../DialogHostTests.cs | 4 +- .../MaterialDesignThemes.Wpf.Tests.csproj | 8 --- 12 files changed, 38 insertions(+), 117 deletions(-) delete mode 100644 tests/MaterialDesignThemes.UITests/TUnit/IsCloseToExtensions.cs diff --git a/.editorconfig b/.editorconfig index 6d4b3ee65d..2a83363e25 100644 --- a/.editorconfig +++ b/.editorconfig @@ -132,6 +132,9 @@ csharp_style_expression_bodied_indexers = true:silent csharp_style_expression_bodied_lambdas = true:silent csharp_style_expression_bodied_local_functions = false:silent +# TUnit0031: Async void methods and lambdas are not allowed +dotnet_diagnostic.TUnit0031.severity = suggestion + [*.{cs,vb}] #### Naming styles #### @@ -188,3 +191,4 @@ dotnet_style_prefer_auto_properties = true:silent dotnet_style_object_initializer = true:suggestion dotnet_style_collection_initializer = true:suggestion dotnet_style_prefer_simplified_boolean_expressions = true:suggestion + diff --git a/Directory.packages.props b/Directory.packages.props index 3dc3a40120..7b6068480f 100644 --- a/Directory.packages.props +++ b/Directory.packages.props @@ -6,37 +6,37 @@ - + - + - - - - - + + + + + - + - - + + - - - - + + + + - + - - - + + + diff --git a/global.json b/global.json index c461cbf6c0..472c185ad7 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "10.0.102", + "version": "10.0.301", "rollForward": "latestMinor" }, "test": { diff --git a/tests/MaterialDesignThemes.UITests/MaterialDesignThemes.UITests.csproj b/tests/MaterialDesignThemes.UITests/MaterialDesignThemes.UITests.csproj index 7e8746ae2c..cc91938039 100644 --- a/tests/MaterialDesignThemes.UITests/MaterialDesignThemes.UITests.csproj +++ b/tests/MaterialDesignThemes.UITests/MaterialDesignThemes.UITests.csproj @@ -19,7 +19,6 @@ - diff --git a/tests/MaterialDesignThemes.UITests/TUnit/IsCloseToExtensions.cs b/tests/MaterialDesignThemes.UITests/TUnit/IsCloseToExtensions.cs deleted file mode 100644 index e70a7fc67a..0000000000 --- a/tests/MaterialDesignThemes.UITests/TUnit/IsCloseToExtensions.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System.Numerics; -using System.Runtime.CompilerServices; -using TUnit.Assertions.Core; - -namespace MaterialDesignThemes.Tests.TUnit; - -public static class IsCloseToExtensions -{ - public static IsCloseToAssertion IsCloseTo( - this IAssertionSource source, double expected, double precision, - [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, - [CallerArgumentExpression(nameof(precision))] string? precisionExpression = null) - { - source.Context.ExpressionBuilder.Append(".IsCloseTo("); - source.Context.ExpressionBuilder.Append(expectedExpression); - source.Context.ExpressionBuilder.Append(", "); - source.Context.ExpressionBuilder.Append(precisionExpression); - source.Context.ExpressionBuilder.Append(')'); - return new IsCloseToAssertion(source.Context, expected, precision); - } - - public static IsCloseToAssertion IsCloseTo( - this IAssertionSource source, float expected, float precision, - [CallerArgumentExpression(nameof(expected))] string? expectedExpression = null, - [CallerArgumentExpression(nameof(precision))] string? precisionExpression = null) - { - source.Context.ExpressionBuilder.Append(".IsCloseTo("); - source.Context.ExpressionBuilder.Append(expectedExpression); - source.Context.ExpressionBuilder.Append(", "); - source.Context.ExpressionBuilder.Append(precisionExpression); - source.Context.ExpressionBuilder.Append(')'); - return new IsCloseToAssertion(source.Context, expected, precision); - } -} - -public class IsCloseToAssertion(AssertionContext context, TValue expected, TValue precision) : Assertion(context) - where TValue : IFloatingPoint, INumberBase -{ - protected override string GetExpectation() - { - DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new(15, 1); - defaultInterpolatedStringHandler.AppendLiteral("to be within "); - defaultInterpolatedStringHandler.AppendFormatted($"\"{precision}\""); - defaultInterpolatedStringHandler.AppendLiteral(" of "); - defaultInterpolatedStringHandler.AppendFormatted($"\"{expected}\""); - return defaultInterpolatedStringHandler.ToStringAndClear(); - } - - protected override Task CheckAsync(EvaluationMetadata metadata) - { - TValue? actualValue = metadata.Value; - Exception? exception = metadata.Exception; - if (exception != null) - { - return Task.FromResult(AssertionResult.Failed("threw " + exception.GetType().FullName)); - } - if (actualValue is null) - { - return Task.FromResult(AssertionResult.Failed($"found ")); - } - - TValue difference = actualValue - expected; - TValue absoluteDifference = TValue.Abs(difference); - bool isInRange = absoluteDifference <= precision; - - if (isInRange) - { - return Task.FromResult(AssertionResult.Passed); - } - return Task.FromResult(AssertionResult.Failed($"found {actualValue}")); - } -} diff --git a/tests/MaterialDesignThemes.UITests/TestBase.cs b/tests/MaterialDesignThemes.UITests/TestBase.cs index 93e6ccae1c..b80e7288e7 100644 --- a/tests/MaterialDesignThemes.UITests/TestBase.cs +++ b/tests/MaterialDesignThemes.UITests/TestBase.cs @@ -16,6 +16,7 @@ [assembly: GenerateHelpers(typeof(DrawerHost))] [assembly: GenerateHelpers(typeof(NumericUpDown))] [assembly: GenerateHelpers(typeof(PopupBox))] +[assembly: GenerateHelpers(typeof(ComboBoxPopup))] [assembly: GenerateHelpers(typeof(SmartHint))] [assembly: GenerateHelpers(typeof(TimePicker))] [assembly: GenerateHelpers(typeof(TreeListView))] diff --git a/tests/MaterialDesignThemes.UITests/WPF/ComboBoxes/ComboBoxTests.cs b/tests/MaterialDesignThemes.UITests/WPF/ComboBoxes/ComboBoxTests.cs index d74644be00..c784351d2e 100644 --- a/tests/MaterialDesignThemes.UITests/WPF/ComboBoxes/ComboBoxTests.cs +++ b/tests/MaterialDesignThemes.UITests/WPF/ComboBoxes/ComboBoxTests.cs @@ -275,8 +275,6 @@ public async Task ComboBox_BorderShouldDependOnAppliedStyle(string style, double [Description("Issue 3887")] public async Task ComboBox_UsesDropDownBackgroundResource_WhenBackgroundIsNotSet() { - await using var recorder = new TestRecorder(App); - var stackPanel = await LoadXaml($$""" @@ -294,12 +292,11 @@ public async Task ComboBox_UsesDropDownBackgroundResource_WhenBackgroundIsNotSet var comboBox = await stackPanel.GetElement(); await comboBox.LeftClick(Position.RightCenter); + var popup = await Wait.For(async () => await comboBox.GetElement("PART_Popup")); Color? popupBackground = await popup.GetBackgroundColor(); await Assert.That(popupBackground).IsNotNull(); await Assert.That(popupBackground).IsEqualTo((Color)ColorConverter.ConvertFromString("#CC336699")); - - recorder.Success(); } } diff --git a/tests/MaterialDesignThemes.UITests/WPF/TabControls/TabControlTests.cs b/tests/MaterialDesignThemes.UITests/WPF/TabControls/TabControlTests.cs index bfd6e48b78..ca4e7a320d 100644 --- a/tests/MaterialDesignThemes.UITests/WPF/TabControls/TabControlTests.cs +++ b/tests/MaterialDesignThemes.UITests/WPF/TabControls/TabControlTests.cs @@ -284,7 +284,7 @@ public async Task ScrollingTabs_WithNavigationPanelLeft_ShouldCorrectlySetIsOver Visibility navigationPanelVisibility = await navigationPanel.GetVisibility(); // Assert - await Assert.That(isOverflowing).IsEqualTo(true); + await Assert.That(isOverflowing).IsTrue(); await Assert.That(navigationPanelVisibility).IsEqualTo(Visibility.Visible); recorder.Success(); @@ -322,7 +322,7 @@ public async Task ScrollingTabs_WithNavigationPanelRight_ShouldCorrectlySetIsOve Visibility navigationPanelVisibility = await navigationPanel.GetVisibility(); // Assert - await Assert.That(isOverflowing).IsEqualTo(true); + await Assert.That(isOverflowing).IsTrue(); await Assert.That(navigationPanelVisibility).IsEqualTo(Visibility.Visible); recorder.Success(); diff --git a/tests/MaterialDesignThemes.Wpf.Tests/ButtonProgressAssistTests.cs b/tests/MaterialDesignThemes.Wpf.Tests/ButtonProgressAssistTests.cs index d7b1e72aa8..69a46665b5 100644 --- a/tests/MaterialDesignThemes.Wpf.Tests/ButtonProgressAssistTests.cs +++ b/tests/MaterialDesignThemes.Wpf.Tests/ButtonProgressAssistTests.cs @@ -52,7 +52,7 @@ public async Task TestIsIndeterminateProperty() Button testElement = new(); // Assert defaults await Assert.That(ButtonProgressAssist.IsIndeterminateProperty.Name).IsEqualTo("IsIndeterminate"); - await Assert.That(ButtonProgressAssist.GetIsIndeterminate(testElement)).IsEqualTo(default(bool)); + await Assert.That(ButtonProgressAssist.GetIsIndeterminate(testElement)).IsFalse(); // Assert setting works ButtonProgressAssist.SetIsIndeterminate(testElement, false); @@ -65,7 +65,7 @@ public async Task TestIndicatorForegroundProperty() Button testElement = new(); // Assert defaults await Assert.That(ButtonProgressAssist.IndicatorForegroundProperty.Name).IsEqualTo("IndicatorForeground"); - await Assert.That(ButtonProgressAssist.GetIndicatorForeground(testElement)).IsEqualTo(default(Brush)); + await Assert.That(ButtonProgressAssist.GetIndicatorForeground(testElement)).IsNull(); // Assert setting works ButtonProgressAssist.SetIndicatorForeground(testElement, Brushes.LightBlue); @@ -78,7 +78,7 @@ public async Task TestIndicatorBackgroundProperty() Button testElement = new(); // Assert defaults await Assert.That(ButtonProgressAssist.IndicatorBackgroundProperty.Name).IsEqualTo("IndicatorBackground"); - await Assert.That(ButtonProgressAssist.GetIndicatorBackground(testElement)).IsEqualTo(default(Brush)); + await Assert.That(ButtonProgressAssist.GetIndicatorBackground(testElement)).IsNull(); // Assert setting works ButtonProgressAssist.SetIndicatorBackground(testElement, Brushes.DarkGoldenrod); @@ -91,7 +91,7 @@ public async Task TestIsIndicatorVisibleProperty() Button testElement = new(); // Assert defaults await Assert.That(ButtonProgressAssist.IsIndicatorVisibleProperty.Name).IsEqualTo("IsIndicatorVisible"); - await Assert.That(ButtonProgressAssist.GetIsIndicatorVisible(testElement)).IsEqualTo(default(bool)); + await Assert.That(ButtonProgressAssist.GetIsIndicatorVisible(testElement)).IsFalse(); // Assert setting works ButtonProgressAssist.SetIsIndicatorVisible(testElement, true); diff --git a/tests/MaterialDesignThemes.Wpf.Tests/DataGridAssistTests.cs b/tests/MaterialDesignThemes.Wpf.Tests/DataGridAssistTests.cs index 4160426dc8..e131f1bec3 100644 --- a/tests/MaterialDesignThemes.Wpf.Tests/DataGridAssistTests.cs +++ b/tests/MaterialDesignThemes.Wpf.Tests/DataGridAssistTests.cs @@ -10,7 +10,7 @@ public async Task TestAutoGeneratedCheckBoxStyleProperty() DataGrid testElement = new(); // Assert defaults await Assert.That(DataGridAssist.AutoGeneratedCheckBoxStyleProperty.Name).IsEqualTo("AutoGeneratedCheckBoxStyle"); - await Assert.That(DataGridAssist.GetAutoGeneratedCheckBoxStyle(testElement)).IsEqualTo(default(Style)); + await Assert.That(DataGridAssist.GetAutoGeneratedCheckBoxStyle(testElement)).IsNull(); // Assert setting works var style = new Style(); @@ -24,7 +24,7 @@ public async Task TestAutoGeneratedEditingCheckBoxStyleProperty() DataGrid testElement = new(); // Assert defaults await Assert.That(DataGridAssist.AutoGeneratedEditingCheckBoxStyleProperty.Name).IsEqualTo("AutoGeneratedEditingCheckBoxStyle"); - await Assert.That(DataGridAssist.GetAutoGeneratedEditingCheckBoxStyle(testElement)).IsEqualTo(default(Style)); + await Assert.That(DataGridAssist.GetAutoGeneratedEditingCheckBoxStyle(testElement)).IsNull(); // Assert setting works var style = new Style(); @@ -38,7 +38,7 @@ public async Task TestAutoGeneratedTextStyleProperty() DataGrid testElement = new(); // Assert defaults await Assert.That(DataGridAssist.AutoGeneratedTextStyleProperty.Name).IsEqualTo("AutoGeneratedTextStyle"); - await Assert.That(DataGridAssist.GetAutoGeneratedTextStyle(testElement)).IsEqualTo(default(Style)); + await Assert.That(DataGridAssist.GetAutoGeneratedTextStyle(testElement)).IsNull(); // Assert setting works var style = new Style(); @@ -52,7 +52,7 @@ public async Task TestAutoGeneratedEditingTextStyleProperty() DataGrid testElement = new(); // Assert defaults await Assert.That(DataGridAssist.AutoGeneratedEditingTextStyleProperty.Name).IsEqualTo("AutoGeneratedEditingTextStyle"); - await Assert.That(DataGridAssist.GetAutoGeneratedEditingTextStyle(testElement)).IsEqualTo(default(Style)); + await Assert.That(DataGridAssist.GetAutoGeneratedEditingTextStyle(testElement)).IsNull(); // Assert setting works var style = new Style(); @@ -96,7 +96,7 @@ public async Task TestEnableEditBoxAssistProperty() DataGrid testElement = new(); // Assert defaults await Assert.That(DataGridAssist.EnableEditBoxAssistProperty.Name).IsEqualTo("EnableEditBoxAssist"); - await Assert.That(DataGridAssist.GetEnableEditBoxAssist(testElement)).IsEqualTo(default(bool)); + await Assert.That(DataGridAssist.GetEnableEditBoxAssist(testElement)).IsFalse(); // Assert setting works DataGridAssist.SetEnableEditBoxAssist(testElement, true); diff --git a/tests/MaterialDesignThemes.Wpf.Tests/DialogHostTests.cs b/tests/MaterialDesignThemes.Wpf.Tests/DialogHostTests.cs index 17247e6d90..a3c403ccb6 100644 --- a/tests/MaterialDesignThemes.Wpf.Tests/DialogHostTests.cs +++ b/tests/MaterialDesignThemes.Wpf.Tests/DialogHostTests.cs @@ -136,12 +136,12 @@ public async Task CannotShowDialogWhileItIsAlreadyOpen() dialogHost.Identifier = id; await DialogHost.Show("Content", id, - new DialogOpenedEventHandler((async (sender, args) => + new DialogOpenedEventHandler(async (sender, args) => { var ex = await Assert.ThrowsAsync(() => DialogHost.Show("Content", id)); args.Session.Close(); await Assert.That(ex?.Message).IsEqualTo("DialogHost is already open."); - }))); + })); } [Test] diff --git a/tests/MaterialDesignThemes.Wpf.Tests/MaterialDesignThemes.Wpf.Tests.csproj b/tests/MaterialDesignThemes.Wpf.Tests/MaterialDesignThemes.Wpf.Tests.csproj index d16a480ca6..f5db9f99b1 100644 --- a/tests/MaterialDesignThemes.Wpf.Tests/MaterialDesignThemes.Wpf.Tests.csproj +++ b/tests/MaterialDesignThemes.Wpf.Tests/MaterialDesignThemes.Wpf.Tests.csproj @@ -5,9 +5,6 @@ Exe true - - - @@ -18,11 +15,6 @@ - - - - - From f85bb3979739f2f48ee004318c56a7540234f8d0 Mon Sep 17 00:00:00 2001 From: Kevin Bost Date: Thu, 20 Aug 2026 21:14:51 -0700 Subject: [PATCH 4/4] feat(Theme): Add ComboBox dropdown background property Introduces a dedicated `DropDowns.Background` property to the `ComboBox` theme object, allowing programmatic control over the `MaterialDesign.Brush.ComboBox.DropDown.Background` brush. This formalizes the dropdown background as a configurable theme aspect within the `Theme` definition and sets its default values for light and dark themes. --- .../ResourceDictionaryExtensions.g.cs | 2 ++ src/MaterialDesignThemes.Wpf/Theme.g.cs | 20 +++++++++++++++++++ .../ThemeExtensions.g.cs | 2 ++ .../Themes/MaterialDesignTheme.Dark.xaml | 2 +- .../Themes/MaterialDesignTheme.Light.xaml | 2 +- 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/MaterialDesignThemes.Wpf/ResourceDictionaryExtensions.g.cs b/src/MaterialDesignThemes.Wpf/ResourceDictionaryExtensions.g.cs index 56a878fc38..4701fc10ad 100644 --- a/src/MaterialDesignThemes.Wpf/ResourceDictionaryExtensions.g.cs +++ b/src/MaterialDesignThemes.Wpf/ResourceDictionaryExtensions.g.cs @@ -43,6 +43,7 @@ private static partial void LoadThemeColors(ResourceDictionary resourceDictionar theme.ComboBoxes.HoverBorder = GetColor(resourceDictionary, "MaterialDesign.Brush.ComboBox.HoverBorder", "MaterialDesignBody"); theme.ComboBoxes.Border = GetColor(resourceDictionary, "MaterialDesign.Brush.ComboBox.Border", "MaterialDesignBodyLight", "MaterialDesignCheckBoxOff", "MaterialDesignTextBoxBorder"); theme.ComboBoxes.OutlineBorder = GetColor(resourceDictionary, "MaterialDesign.Brush.ComboBox.OutlineBorder", "MaterialDesignColumnHeader", "MaterialDesignTextAreaBorder"); + theme.ComboBoxes.DropDowns.Background = GetColor(resourceDictionary, "MaterialDesign.Brush.ComboBox.DropDown.Background"); theme.ComboBoxes.Popups.DarkBackground = GetColor(resourceDictionary, "MaterialDesign.Brush.ComboBox.Popup.DarkBackground"); theme.ComboBoxes.Popups.DarkForeground = GetColor(resourceDictionary, "MaterialDesign.Brush.ComboBox.Popup.DarkForeground"); theme.ComboBoxes.Popups.LightBackground = GetColor(resourceDictionary, "MaterialDesign.Brush.ComboBox.Popup.LightBackground"); @@ -164,6 +165,7 @@ private static partial void ApplyThemeColors(ResourceDictionary resourceDictiona SetSolidColorBrush(resourceDictionary, "MaterialDesign.Brush.ComboBox.OutlineBorder", theme.ComboBoxes.OutlineBorder); SetSolidColorBrush(resourceDictionary, "MaterialDesignColumnHeader", theme.ComboBoxes.OutlineBorder); SetSolidColorBrush(resourceDictionary, "MaterialDesignTextAreaBorder", theme.ComboBoxes.OutlineBorder); + SetSolidColorBrush(resourceDictionary, "MaterialDesign.Brush.ComboBox.DropDown.Background", theme.ComboBoxes.DropDowns.Background); SetSolidColorBrush(resourceDictionary, "MaterialDesign.Brush.ComboBox.Popup.DarkBackground", theme.ComboBoxes.Popups.DarkBackground); SetSolidColorBrush(resourceDictionary, "MaterialDesign.Brush.ComboBox.Popup.DarkForeground", theme.ComboBoxes.Popups.DarkForeground); SetSolidColorBrush(resourceDictionary, "MaterialDesign.Brush.ComboBox.Popup.LightBackground", theme.ComboBoxes.Popups.LightBackground); diff --git a/src/MaterialDesignThemes.Wpf/Theme.g.cs b/src/MaterialDesignThemes.Wpf/Theme.g.cs index 1151bb2cff..9ea4eaa13c 100644 --- a/src/MaterialDesignThemes.Wpf/Theme.g.cs +++ b/src/MaterialDesignThemes.Wpf/Theme.g.cs @@ -353,6 +353,7 @@ public class ComboBox public ComboBox(Theme theme) { _theme = theme ?? throw new ArgumentNullException(nameof(theme)); + DropDowns = new(theme); Popups = new(theme); } @@ -405,8 +406,27 @@ public ColorReference OutlineBorder set => _outlineBorder = value; } + public DropDown DropDowns { get; set; } + public Popup Popups { get; set; } + public class DropDown + { + private readonly Theme _theme; + public DropDown(Theme theme) + { + _theme = theme ?? throw new ArgumentNullException(nameof(theme)); + } + + private ColorReference _background; + public ColorReference Background + { + get => _theme.Resolve(_background); + set => _background = value; + } + + } + public class Popup { private readonly Theme _theme; diff --git a/src/MaterialDesignThemes.Wpf/ThemeExtensions.g.cs b/src/MaterialDesignThemes.Wpf/ThemeExtensions.g.cs index 09af33bef0..cb5e6391b1 100644 --- a/src/MaterialDesignThemes.Wpf/ThemeExtensions.g.cs +++ b/src/MaterialDesignThemes.Wpf/ThemeExtensions.g.cs @@ -48,6 +48,7 @@ public static partial void SetLightTheme(this Theme theme) theme.ComboBoxes.HoverBorder = BaseThemeColors.Black900; theme.ComboBoxes.Border = BaseThemeColors.Black500; theme.ComboBoxes.OutlineBorder = BaseThemeColors.Black700; + theme.ComboBoxes.DropDowns.Background = BaseThemeColors.Neutral900; theme.ComboBoxes.Popups.DarkBackground = BaseThemeColors.Neutral100; theme.ComboBoxes.Popups.DarkForeground = BaseThemeColors.Neutral900; theme.ComboBoxes.Popups.LightBackground = BaseThemeColors.Neutral900; @@ -140,6 +141,7 @@ public static partial void SetDarkTheme(this Theme theme) theme.ComboBoxes.HoverBorder = BaseThemeColors.White900; theme.ComboBoxes.Border = BaseThemeColors.White500; theme.ComboBoxes.OutlineBorder = BaseThemeColors.White700; + theme.ComboBoxes.DropDowns.Background = BaseThemeColors.Neutral100; theme.ComboBoxes.Popups.DarkBackground = BaseThemeColors.Neutral100; theme.ComboBoxes.Popups.DarkForeground = BaseThemeColors.Neutral900; theme.ComboBoxes.Popups.LightBackground = BaseThemeColors.Neutral900; diff --git a/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Dark.xaml b/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Dark.xaml index daa81fe88c..c4d66b89a1 100644 --- a/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Dark.xaml +++ b/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Dark.xaml @@ -26,10 +26,10 @@ + - diff --git a/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Light.xaml b/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Light.xaml index e972991495..fed8cff81b 100644 --- a/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Light.xaml +++ b/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Light.xaml @@ -26,10 +26,10 @@ + -