Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -557,7 +557,7 @@
<ContentControl>
<ScrollViewer MinHeight="1"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
Background="{Binding Background, ElementName=PART_Popup}">
Background="Transparent">
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" />
</ScrollViewer>
</ContentControl>
Expand Down Expand Up @@ -796,8 +796,8 @@
<Condition SourceName="PART_Popup" Property="wpf:ColorZoneAssist.Mode" Value="Standard" />
</MultiTrigger.Conditions>
<Setter Property="TextElement.Foreground" Value="{DynamicResource MaterialDesign.Brush.Foreground}" />
<Setter TargetName="PART_Popup" Property="Background" Value="{Binding Tag, RelativeSource={RelativeSource Self}, Converter={x:Static converters:RemoveAlphaBrushConverter.Instance}}" />
<Setter TargetName="PART_Popup" Property="Tag" Value="{DynamicResource MaterialDesign.Brush.Background}" />
<Setter TargetName="PART_Popup" Property="Background" Value="{Binding Tag, RelativeSource={RelativeSource Self}}" />
<Setter TargetName="PART_Popup" Property="Tag" Value="{DynamicResource MaterialDesign.Brush.ComboBox.DropDown.Background}" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.FilledBackground" ResourceKey="White100" />
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.HoverBackground" ResourceKey="White100" />
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.OutlineInactiveBorder" ResourceKey="White200" />
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.DropDown.Background" ResourceKey="Neutral100" />
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.Popup.DarkBackground" ResourceKey="Neutral100" />
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.Popup.DarkForeground" ResourceKey="Neutral900" />
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.Popup.LightBackground" ResourceKey="Neutral900" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@
<Grid MaxHeight="{TemplateBinding MaxDropDownHeight}" UseLayoutRounding="True">
<AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
<Border x:Name="shadow"
Background="{DynamicResource MaterialDesign.Brush.Background}"
Background="{DynamicResource MaterialDesign.Brush.ComboBox.DropDown.Background}"
BorderThickness="1"
CornerRadius="2"
Effect="{DynamicResource MaterialDesignShadowDepth2}" />
</AdornerDecorator>
<Border x:Name="dropDownBorder"
MinWidth="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=DataGridCell}}"
Margin="{Binding ElementName=shadow, Path=Margin, Mode=OneWay}"
Background="Transparent"
Background="{DynamicResource MaterialDesign.Brush.ComboBox.DropDown.Background}"
BorderBrush="{DynamicResource MaterialDesign.Brush.DataGrid.ComboBoxHover}"
BorderThickness="1"
CornerRadius="2">
Expand Down Expand Up @@ -285,15 +285,15 @@
<Grid MaxHeight="{TemplateBinding MaxDropDownHeight}" UseLayoutRounding="True">
<AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
<Border x:Name="shadow"
Background="{DynamicResource MaterialDesign.Brush.Background}"
Background="{DynamicResource MaterialDesign.Brush.ComboBox.DropDown.Background}"
BorderThickness="1"
CornerRadius="2"
Effect="{DynamicResource MaterialDesignShadowDepth2}" />
</AdornerDecorator>
<Border x:Name="dropDownBorder"
MinWidth="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=DataGridCell}}"
Margin="{Binding ElementName=shadow, Path=Margin, Mode=OneWay}"
Background="Transparent"
Background="{DynamicResource MaterialDesign.Brush.ComboBox.DropDown.Background}"
BorderBrush="{DynamicResource MaterialDesign.Brush.DataGrid.ComboBoxHover}"
BorderThickness="1"
CornerRadius="2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.FilledBackground" ResourceKey="Black50" />
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.HoverBackground" ResourceKey="Black100" />
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.OutlineInactiveBorder" ResourceKey="Black200" />
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.DropDown.Background" ResourceKey="Neutral900" />
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.Popup.DarkBackground" ResourceKey="Neutral100" />
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.Popup.DarkForeground" ResourceKey="Neutral900" />
<colors:StaticResource x:Key="MaterialDesign.Brush.ComboBox.Popup.LightBackground" ResourceKey="Neutral900" />
Expand Down
9 changes: 9 additions & 0 deletions src/MaterialDesignToolkit.ResourceGeneration/ThemeColors.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
33 changes: 33 additions & 0 deletions tests/MaterialDesignThemes.UITests/WPF/ComboBoxes/ComboBoxTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System.Windows.Media;
using MaterialDesignThemes.UITests.WPF.TextBoxes;

namespace MaterialDesignThemes.UITests.WPF.ComboBoxes;
Expand Down Expand Up @@ -269,4 +270,36 @@
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<StackPanel>($$"""
<StackPanel>
<ComboBox Width="200">
<ComboBox.Resources>
<SolidColorBrush x:Key="MaterialDesign.Brush.ComboBox.DropDown.Background"
Color="#CC336699" />
</ComboBox.Resources>
<ComboBoxItem Content="Android" />
<ComboBoxItem Content="iOS" />
<ComboBoxItem Content="Linux" />
</ComboBox>
</StackPanel>
""");

var comboBox = await stackPanel.GetElement<ComboBox>();
await comboBox.LeftClick(Position.RightCenter);

var popup = await Wait.For(async () => await comboBox.GetElement<ComboBoxPopup>("PART_Popup"));
Color? popupBackground = await popup.GetBackgroundColor();

Check failure on line 298 in tests/MaterialDesignThemes.UITests/WPF/ComboBoxes/ComboBoxTests.cs

View workflow job for this annotation

GitHub Actions / Build artifacts / Build and Test

The type 'MaterialDesignThemes.Wpf.ComboBoxPopup' cannot be used as type parameter 'T' in the generic type or method 'ControlGeneratedExtensions.GetBackgroundColor<T>(IVisualElement<T>)'. There is no implicit reference conversion from 'MaterialDesignThemes.Wpf.ComboBoxPopup' to 'System.Windows.Controls.Control'.

Check failure on line 298 in tests/MaterialDesignThemes.UITests/WPF/ComboBoxes/ComboBoxTests.cs

View workflow job for this annotation

GitHub Actions / Build artifacts / Build and Test

The type 'MaterialDesignThemes.Wpf.ComboBoxPopup' cannot be used as type parameter 'T' in the generic type or method 'ControlGeneratedExtensions.GetBackgroundColor<T>(IVisualElement<T>)'. There is no implicit reference conversion from 'MaterialDesignThemes.Wpf.ComboBoxPopup' to 'System.Windows.Controls.Control'.

await Assert.That(popupBackground).IsNotNull();
await Assert.That(popupBackground).IsEqualTo((Color)ColorConverter.ConvertFromString("#CC336699"));

recorder.Success();
}
}
7 changes: 7 additions & 0 deletions tests/MaterialDesignThemes.UITests/WPF/Theme/ThemeTests.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ private partial string GetXamlWrapPanel()
<TextBlock Text="ComboBox.HoverBorder" Background="{StaticResource MaterialDesign.Brush.ComboBox.HoverBorder}" />
<TextBlock Text="ComboBox.Border" Background="{StaticResource MaterialDesign.Brush.ComboBox.Border}" />
<TextBlock Text="ComboBox.OutlineBorder" Background="{StaticResource MaterialDesign.Brush.ComboBox.OutlineBorder}" />
<TextBlock Text="ComboBox.DropDown.Background" Background="{StaticResource MaterialDesign.Brush.ComboBox.DropDown.Background}" />
<TextBlock Text="ComboBox.Popup.DarkBackground" Background="{StaticResource MaterialDesign.Brush.ComboBox.Popup.DarkBackground}" />
<TextBlock Text="ComboBox.Popup.DarkForeground" Background="{StaticResource MaterialDesign.Brush.ComboBox.Popup.DarkForeground}" />
<TextBlock Text="ComboBox.Popup.LightBackground" Background="{StaticResource MaterialDesign.Brush.ComboBox.Popup.LightBackground}" />
Expand Down Expand Up @@ -345,6 +346,11 @@ private partial async Task AssertAllThemeBrushesSet(IVisualElement<WrapPanel> pa
Color? textBlockBackground = await textBlock.GetBackgroundColor();
await Assert.That(textBlockBackground).IsEqualTo(await GetResourceColor("MaterialDesign.Brush.ComboBox.OutlineBorder"));
}
{
IVisualElement<TextBlock> textBlock = await panel.GetElement<TextBlock>("[Text=\"ComboBox.DropDown.Background\"]");
Color? textBlockBackground = await textBlock.GetBackgroundColor();
await Assert.That(textBlockBackground).IsEqualTo(await GetResourceColor("MaterialDesign.Brush.ComboBox.DropDown.Background"));
}
{
IVisualElement<TextBlock> textBlock = await panel.GetElement<TextBlock>("[Text=\"ComboBox.Popup.DarkBackground\"]");
Color? textBlockBackground = await textBlock.GetBackgroundColor();
Expand Down Expand Up @@ -955,6 +961,7 @@ private static IEnumerable<string> 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";
Expand Down
Loading