Skip to content

Commit 2a00ffb

Browse files
authored
Adds ComboBox dropdown background brush (#4059)
* 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. * 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. * 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.
1 parent d76c6d4 commit 2a00ffb

21 files changed

Lines changed: 117 additions & 121 deletions

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ csharp_style_expression_bodied_indexers = true:silent
132132
csharp_style_expression_bodied_lambdas = true:silent
133133
csharp_style_expression_bodied_local_functions = false:silent
134134

135+
# TUnit0031: Async void methods and lambdas are not allowed
136+
dotnet_diagnostic.TUnit0031.severity = suggestion
137+
135138
[*.{cs,vb}]
136139
#### Naming styles ####
137140

@@ -188,3 +191,4 @@ dotnet_style_prefer_auto_properties = true:silent
188191
dotnet_style_object_initializer = true:suggestion
189192
dotnet_style_collection_initializer = true:suggestion
190193
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
194+

Directory.packages.props

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,37 @@
66
</PropertyGroup>
77
<ItemGroup>
88
<PackageVersion Include="BluwolfIcons" Version="1.0.1" />
9-
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.4.0" />
9+
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.4.2" />
1010
<PackageVersion Include="Dragablz" Version="0.0.3.234" />
1111
<PackageVersion Include="GitHubActionsTestLogger" Version="3.0.1" />
12-
<PackageVersion Include="Humanizer" Version="2.14.1" />
12+
<PackageVersion Include="Humanizer" Version="3.0.10" />
1313
<PackageVersion Include="MahApps.Metro" Version="2.4.11" />
1414
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
15-
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
16-
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.8.0" />
17-
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
18-
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />
19-
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.8.0" />
15+
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="5.3.0" PrivateAssets="all" />
16+
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="5.3.0" />
17+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.3.0" />
18+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="5.3.0" />
19+
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="5.3.0" />
2020
<PackageVersion Include="Microsoft.Composition" Version="1.0.31" />
2121
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
2222
<PackageVersion Include="Microsoft.NETCore.Platforms" Version="7.0.4" />
23-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
23+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.6.0" />
2424
<PackageVersion Include="Microsoft.Toolkit.MVVM" Version="7.1.2" />
25-
<PackageVersion Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.77" />
26-
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
25+
<PackageVersion Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.142" />
26+
<PackageVersion Include="Newtonsoft.Json" Version="13.0.4" />
2727
<PackageVersion Include="Polyfill" Version="8.8.1" />
2828
<PackageVersion Include="Shouldly" Version="4.3.0" />
29-
<PackageVersion Include="ShowMeTheXAML" Version="2.0.0" />
30-
<PackageVersion Include="ShowMeTheXAML.AvalonEdit" Version="2.0.0" />
31-
<PackageVersion Include="ShowMeTheXAML.MSBuild" Version="2.0.0" />
32-
<PackageVersion Include="System.CommandLine" Version="2.0.2" />
29+
<PackageVersion Include="ShowMeTheXAML" Version="2.1.1" />
30+
<PackageVersion Include="ShowMeTheXAML.AvalonEdit" Version="2.1.1" />
31+
<PackageVersion Include="ShowMeTheXAML.MSBuild" Version="2.1.1" />
32+
<PackageVersion Include="System.CommandLine" Version="2.0.9" />
3333
<PackageVersion Include="System.Memory" Version="4.6.3" />
3434
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
3535
<PackageVersion Include="System.Private.Uri" Version="4.3.2" />
36-
<PackageVersion Include="System.ValueTuple" Version="4.6.1" />
36+
<PackageVersion Include="System.ValueTuple" Version="4.6.2" />
3737
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
38-
<PackageVersion Include="TUnit" Version="1.9.45" />
39-
<PackageVersion Include="VirtualizingWrapPanel" Version="1.5.8" />
40-
<PackageVersion Include="XAMLTest" Version="1.3.1-ci662" />
38+
<PackageVersion Include="TUnit" Version="1.53.0" />
39+
<PackageVersion Include="VirtualizingWrapPanel" Version="2.5.1" />
40+
<PackageVersion Include="XAMLTest" Version="1.3.1" />
4141
</ItemGroup>
4242
</Project>

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "10.0.102",
3+
"version": "10.0.301",
44
"rollForward": "latestMinor"
55
},
66
"test": {

src/MaterialDesignThemes.Wpf/ResourceDictionaryExtensions.g.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ private static partial void LoadThemeColors(ResourceDictionary resourceDictionar
4343
theme.ComboBoxes.HoverBorder = GetColor(resourceDictionary, "MaterialDesign.Brush.ComboBox.HoverBorder", "MaterialDesignBody");
4444
theme.ComboBoxes.Border = GetColor(resourceDictionary, "MaterialDesign.Brush.ComboBox.Border", "MaterialDesignBodyLight", "MaterialDesignCheckBoxOff", "MaterialDesignTextBoxBorder");
4545
theme.ComboBoxes.OutlineBorder = GetColor(resourceDictionary, "MaterialDesign.Brush.ComboBox.OutlineBorder", "MaterialDesignColumnHeader", "MaterialDesignTextAreaBorder");
46+
theme.ComboBoxes.DropDowns.Background = GetColor(resourceDictionary, "MaterialDesign.Brush.ComboBox.DropDown.Background");
4647
theme.ComboBoxes.Popups.DarkBackground = GetColor(resourceDictionary, "MaterialDesign.Brush.ComboBox.Popup.DarkBackground");
4748
theme.ComboBoxes.Popups.DarkForeground = GetColor(resourceDictionary, "MaterialDesign.Brush.ComboBox.Popup.DarkForeground");
4849
theme.ComboBoxes.Popups.LightBackground = GetColor(resourceDictionary, "MaterialDesign.Brush.ComboBox.Popup.LightBackground");
@@ -164,6 +165,7 @@ private static partial void ApplyThemeColors(ResourceDictionary resourceDictiona
164165
SetSolidColorBrush(resourceDictionary, "MaterialDesign.Brush.ComboBox.OutlineBorder", theme.ComboBoxes.OutlineBorder);
165166
SetSolidColorBrush(resourceDictionary, "MaterialDesignColumnHeader", theme.ComboBoxes.OutlineBorder);
166167
SetSolidColorBrush(resourceDictionary, "MaterialDesignTextAreaBorder", theme.ComboBoxes.OutlineBorder);
168+
SetSolidColorBrush(resourceDictionary, "MaterialDesign.Brush.ComboBox.DropDown.Background", theme.ComboBoxes.DropDowns.Background);
167169
SetSolidColorBrush(resourceDictionary, "MaterialDesign.Brush.ComboBox.Popup.DarkBackground", theme.ComboBoxes.Popups.DarkBackground);
168170
SetSolidColorBrush(resourceDictionary, "MaterialDesign.Brush.ComboBox.Popup.DarkForeground", theme.ComboBoxes.Popups.DarkForeground);
169171
SetSolidColorBrush(resourceDictionary, "MaterialDesign.Brush.ComboBox.Popup.LightBackground", theme.ComboBoxes.Popups.LightBackground);

src/MaterialDesignThemes.Wpf/Theme.g.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ public class ComboBox
353353
public ComboBox(Theme theme)
354354
{
355355
_theme = theme ?? throw new ArgumentNullException(nameof(theme));
356+
DropDowns = new(theme);
356357
Popups = new(theme);
357358
}
358359

@@ -405,8 +406,27 @@ public ColorReference OutlineBorder
405406
set => _outlineBorder = value;
406407
}
407408

409+
public DropDown DropDowns { get; set; }
410+
408411
public Popup Popups { get; set; }
409412

413+
public class DropDown
414+
{
415+
private readonly Theme _theme;
416+
public DropDown(Theme theme)
417+
{
418+
_theme = theme ?? throw new ArgumentNullException(nameof(theme));
419+
}
420+
421+
private ColorReference _background;
422+
public ColorReference Background
423+
{
424+
get => _theme.Resolve(_background);
425+
set => _background = value;
426+
}
427+
428+
}
429+
410430
public class Popup
411431
{
412432
private readonly Theme _theme;

src/MaterialDesignThemes.Wpf/ThemeExtensions.g.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public static partial void SetLightTheme(this Theme theme)
4848
theme.ComboBoxes.HoverBorder = BaseThemeColors.Black900;
4949
theme.ComboBoxes.Border = BaseThemeColors.Black500;
5050
theme.ComboBoxes.OutlineBorder = BaseThemeColors.Black700;
51+
theme.ComboBoxes.DropDowns.Background = BaseThemeColors.Neutral900;
5152
theme.ComboBoxes.Popups.DarkBackground = BaseThemeColors.Neutral100;
5253
theme.ComboBoxes.Popups.DarkForeground = BaseThemeColors.Neutral900;
5354
theme.ComboBoxes.Popups.LightBackground = BaseThemeColors.Neutral900;
@@ -140,6 +141,7 @@ public static partial void SetDarkTheme(this Theme theme)
140141
theme.ComboBoxes.HoverBorder = BaseThemeColors.White900;
141142
theme.ComboBoxes.Border = BaseThemeColors.White500;
142143
theme.ComboBoxes.OutlineBorder = BaseThemeColors.White700;
144+
theme.ComboBoxes.DropDowns.Background = BaseThemeColors.Neutral100;
143145
theme.ComboBoxes.Popups.DarkBackground = BaseThemeColors.Neutral100;
144146
theme.ComboBoxes.Popups.DarkForeground = BaseThemeColors.Neutral900;
145147
theme.ComboBoxes.Popups.LightBackground = BaseThemeColors.Neutral900;

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ComboBox.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@
534534
PopupAnimation="Fade"
535535
RelativeHorizontalOffset="-6"
536536
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
537-
Tag="{DynamicResource MaterialDesign.Brush.Background}"
537+
Tag="{DynamicResource MaterialDesign.Brush.ComboBox.DropDown.Background}"
538538
UpVerticalOffset="15"
539539
UseLayoutRounding="{TemplateBinding UseLayoutRounding}"
540540
VerticalOffset="0">
@@ -557,7 +557,7 @@
557557
<ContentControl>
558558
<ScrollViewer MinHeight="1"
559559
MaxHeight="{TemplateBinding MaxDropDownHeight}"
560-
Background="{Binding Background, ElementName=PART_Popup}">
560+
Background="Transparent">
561561
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" />
562562
</ScrollViewer>
563563
</ContentControl>
@@ -796,8 +796,8 @@
796796
<Condition SourceName="PART_Popup" Property="wpf:ColorZoneAssist.Mode" Value="Standard" />
797797
</MultiTrigger.Conditions>
798798
<Setter Property="TextElement.Foreground" Value="{DynamicResource MaterialDesign.Brush.Foreground}" />
799-
<Setter TargetName="PART_Popup" Property="Background" Value="{Binding Tag, RelativeSource={RelativeSource Self}, Converter={x:Static converters:RemoveAlphaBrushConverter.Instance}}" />
800-
<Setter TargetName="PART_Popup" Property="Tag" Value="{DynamicResource MaterialDesign.Brush.Background}" />
799+
<Setter TargetName="PART_Popup" Property="Background" Value="{Binding Tag, RelativeSource={RelativeSource Self}}" />
800+
<Setter TargetName="PART_Popup" Property="Tag" Value="{DynamicResource MaterialDesign.Brush.ComboBox.DropDown.Background}" />
801801
</MultiTrigger>
802802
<MultiTrigger>
803803
<MultiTrigger.Conditions>

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Dark.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<colors:StaticResource x:Key="MaterialDesign.Brush.ColorZone.LightBackground" ResourceKey="Neutral900" />
2727
<colors:StaticResource x:Key="MaterialDesign.Brush.ColorZone.LightForeground" ResourceKey="Black900" />
2828
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.Disabled" ResourceKey="Neutral300" />
29+
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.DropDown.Background" ResourceKey="Neutral100" />
2930
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.FilledBackground" ResourceKey="White100" />
3031
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.HoverBackground" ResourceKey="White100" />
3132
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.OutlineInactiveBorder" ResourceKey="White200" />

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DataGrid.ComboBox.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@
159159
<Grid MaxHeight="{TemplateBinding MaxDropDownHeight}" UseLayoutRounding="True">
160160
<AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
161161
<Border x:Name="shadow"
162-
Background="{DynamicResource MaterialDesign.Brush.Background}"
162+
Background="{DynamicResource MaterialDesign.Brush.ComboBox.DropDown.Background}"
163163
BorderThickness="1"
164164
CornerRadius="2"
165165
Effect="{DynamicResource MaterialDesignShadowDepth2}" />
166166
</AdornerDecorator>
167167
<Border x:Name="dropDownBorder"
168168
MinWidth="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=DataGridCell}}"
169169
Margin="{Binding ElementName=shadow, Path=Margin, Mode=OneWay}"
170-
Background="Transparent"
170+
Background="{DynamicResource MaterialDesign.Brush.ComboBox.DropDown.Background}"
171171
BorderBrush="{DynamicResource MaterialDesign.Brush.DataGrid.ComboBoxHover}"
172172
BorderThickness="1"
173173
CornerRadius="2">
@@ -285,15 +285,15 @@
285285
<Grid MaxHeight="{TemplateBinding MaxDropDownHeight}" UseLayoutRounding="True">
286286
<AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
287287
<Border x:Name="shadow"
288-
Background="{DynamicResource MaterialDesign.Brush.Background}"
288+
Background="{DynamicResource MaterialDesign.Brush.ComboBox.DropDown.Background}"
289289
BorderThickness="1"
290290
CornerRadius="2"
291291
Effect="{DynamicResource MaterialDesignShadowDepth2}" />
292292
</AdornerDecorator>
293293
<Border x:Name="dropDownBorder"
294294
MinWidth="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=DataGridCell}}"
295295
Margin="{Binding ElementName=shadow, Path=Margin, Mode=OneWay}"
296-
Background="Transparent"
296+
Background="{DynamicResource MaterialDesign.Brush.ComboBox.DropDown.Background}"
297297
BorderBrush="{DynamicResource MaterialDesign.Brush.DataGrid.ComboBoxHover}"
298298
BorderThickness="1"
299299
CornerRadius="2">

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Light.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<colors:StaticResource x:Key="MaterialDesign.Brush.ColorZone.LightBackground" ResourceKey="Neutral900" />
2727
<colors:StaticResource x:Key="MaterialDesign.Brush.ColorZone.LightForeground" ResourceKey="Black900" />
2828
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.Disabled" ResourceKey="Neutral700" />
29+
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.DropDown.Background" ResourceKey="Neutral900" />
2930
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.FilledBackground" ResourceKey="Black50" />
3031
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.HoverBackground" ResourceKey="Black100" />
3132
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.OutlineInactiveBorder" ResourceKey="Black200" />

0 commit comments

Comments
 (0)