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/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/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 e8e423c231..c784351d2e 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,33 @@ 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() + { + var stackPanel = await LoadXaml($$""" + + + + + + + + + + + """); + + 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")); + } } 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.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"; 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 @@ - - - - -