From bc50b646626704a025fd46edd55129cf47cce09d Mon Sep 17 00:00:00 2001 From: Nicolai Henriksen Date: Mon, 12 Feb 2024 22:30:22 +0100 Subject: [PATCH 1/3] Cleanup DialogHost to use nameof() where applicable --- MaterialDesignThemes.Wpf/DialogHost.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/MaterialDesignThemes.Wpf/DialogHost.cs b/MaterialDesignThemes.Wpf/DialogHost.cs index 96b851d3d9..830d65da79 100644 --- a/MaterialDesignThemes.Wpf/DialogHost.cs +++ b/MaterialDesignThemes.Wpf/DialogHost.cs @@ -483,7 +483,7 @@ public string? DialogContentStringFormat } public static readonly DependencyProperty DialogMarginProperty = DependencyProperty.Register( - "DialogMargin", typeof(Thickness), typeof(DialogHost), new PropertyMetadata(default(Thickness))); + nameof(DialogMargin), typeof(Thickness), typeof(DialogHost), new PropertyMetadata(default(Thickness))); public Thickness DialogMargin { @@ -505,7 +505,7 @@ public DialogHostOpenDialogCommandDataContextSource OpenDialogCommandDataContext } public static readonly DependencyProperty CloseOnClickAwayProperty = DependencyProperty.Register( - "CloseOnClickAway", typeof(bool), typeof(DialogHost), new PropertyMetadata(default(bool))); + nameof(CloseOnClickAway), typeof(bool), typeof(DialogHost), new PropertyMetadata(default(bool))); /// /// Indicates whether the dialog will close if the user clicks off the dialog, on the obscured background. @@ -517,7 +517,7 @@ public bool CloseOnClickAway } public static readonly DependencyProperty CloseOnClickAwayParameterProperty = DependencyProperty.Register( - "CloseOnClickAwayParameter", typeof(object), typeof(DialogHost), new PropertyMetadata(default(object))); + nameof(CloseOnClickAwayParameter), typeof(object), typeof(DialogHost), new PropertyMetadata(default(object))); /// /// Parameter to provide to close handlers if an close due to click away is instigated. @@ -529,7 +529,7 @@ public object? CloseOnClickAwayParameter } public static readonly DependencyProperty SnackbarMessageQueueProperty = DependencyProperty.Register( - "SnackbarMessageQueue", typeof(SnackbarMessageQueue), typeof(DialogHost), new PropertyMetadata(default(SnackbarMessageQueue), SnackbarMessageQueuePropertyChangedCallback)); + nameof(SnackbarMessageQueue), typeof(SnackbarMessageQueue), typeof(DialogHost), new PropertyMetadata(default(SnackbarMessageQueue), SnackbarMessageQueuePropertyChangedCallback)); private static void SnackbarMessageQueuePropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { @@ -642,7 +642,7 @@ public bool IsRestoreFocusDisabled public static readonly RoutedEvent DialogOpenedEvent = EventManager.RegisterRoutedEvent( - "DialogOpened", + nameof(DialogOpened), RoutingStrategy.Bubble, typeof(DialogOpenedEventHandler), typeof(DialogHost)); @@ -689,7 +689,7 @@ protected void OnDialogOpened(DialogOpenedEventArgs eventArgs) public static readonly RoutedEvent DialogClosingEvent = EventManager.RegisterRoutedEvent( - "DialogClosing", + nameof(DialogClosing), RoutingStrategy.Bubble, typeof(DialogClosingEventHandler), typeof(DialogHost)); @@ -732,7 +732,7 @@ protected void OnDialogClosing(DialogClosingEventArgs eventArgs) public static readonly RoutedEvent DialogClosedEvent = EventManager.RegisterRoutedEvent( - "DialogClosed", + nameof(DialogClosed), RoutingStrategy.Bubble, typeof(DialogClosedEventHandler), typeof(DialogHost)); From c30dd89bb373d52ff8bffc75bac0454d9fe771dd Mon Sep 17 00:00:00 2001 From: Nicolai Henriksen Date: Mon, 12 Feb 2024 22:32:36 +0100 Subject: [PATCH 2/3] Add DialogHost.DialogCardStyle DP to allow customizing the style of the nested card --- .../WPF/DialogHosts/DialogHostTests.cs | 52 +++++++++++++++++++ MaterialDesignThemes.Wpf/DialogHost.cs | 9 ++++ .../MaterialDesignTheme.DialogHost.xaml | 30 ++++------- 3 files changed, 71 insertions(+), 20 deletions(-) diff --git a/MaterialDesignThemes.UITests/WPF/DialogHosts/DialogHostTests.cs b/MaterialDesignThemes.UITests/WPF/DialogHosts/DialogHostTests.cs index 89181c746a..a21cadb3fc 100644 --- a/MaterialDesignThemes.UITests/WPF/DialogHosts/DialogHostTests.cs +++ b/MaterialDesignThemes.UITests/WPF/DialogHosts/DialogHostTests.cs @@ -480,4 +480,56 @@ public async Task DialogHost_ChangesSelectedRailItem_DoesNotPerformRailChangeWhe recorder.Success(); } + + [Theory] + [InlineData("MaterialDesignElevatedCard")] + [InlineData("MaterialDesignOutlinedCard")] + [Description("Issue 3430")] + public async Task DialogHost_DefaultStyleWithDialogCardStyleApplied_PassesStyleToNestedCard(string dialogCardStyle) + { + await using var recorder = new TestRecorder(App); + + IVisualElement grid = await LoadXaml($$""" + + + + + + + + """); + + IVisualElement dialogHost = await grid.GetElement("DialogHost"); + IVisualElement nestedCard = await dialogHost.GetElement("PART_PopupContentElement"); + + // TODO: Assert the style on the nested card matches what is set in DialogHost.DialogCardStyle + + recorder.Success(); + } + + [Theory] + [InlineData("MaterialDesignElevatedCard")] + [InlineData("MaterialDesignOutlinedCard")] + [Description("Issue 3430")] + public async Task DialogHost_EmbeddedStyleWithDialogCardStyleApplied_PassesStyleToNestedCard(string dialogCardStyle) + { + await using var recorder = new TestRecorder(App); + + IVisualElement grid = await LoadXaml($$""" + + + + + + + + """); + + IVisualElement dialogHost = await grid.GetElement("DialogHost"); + IVisualElement nestedCard = await dialogHost.GetElement("PART_PopupContentElement"); + + // TODO: Assert the style on the nested card matches what is set in DialogHost.DialogCardStyle + + recorder.Success(); + } } diff --git a/MaterialDesignThemes.Wpf/DialogHost.cs b/MaterialDesignThemes.Wpf/DialogHost.cs index 830d65da79..6f885255ba 100644 --- a/MaterialDesignThemes.Wpf/DialogHost.cs +++ b/MaterialDesignThemes.Wpf/DialogHost.cs @@ -494,6 +494,15 @@ public Thickness DialogMargin public static readonly DependencyProperty OpenDialogCommandDataContextSourceProperty = DependencyProperty.Register( nameof(OpenDialogCommandDataContextSource), typeof(DialogHostOpenDialogCommandDataContextSource), typeof(DialogHost), new PropertyMetadata(default(DialogHostOpenDialogCommandDataContextSource))); + public static readonly DependencyProperty DialogCardStyleProperty = DependencyProperty.Register( + nameof(DialogCardStyle), typeof(Style), typeof(DialogHost), new PropertyMetadata(default(Style))); + + public Style DialogCardStyle + { + get => (Style) GetValue(DialogCardStyleProperty); + set => SetValue(DialogCardStyleProperty, value); + } + /// /// Defines how a data context is sourced for a dialog if a /// is passed as the command parameter when using . diff --git a/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DialogHost.xaml b/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DialogHost.xaml index 0171246280..5d91c37b4f 100644 --- a/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DialogHost.xaml +++ b/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DialogHost.xaml @@ -160,6 +160,7 @@ - - - @@ -228,6 +220,9 @@ + + + @@ -406,6 +401,7 @@ @@ -424,16 +421,6 @@ - - - @@ -441,6 +428,9 @@ + + + From 74f5ac6819cc2ae367208c0dd6af278a2de0422c Mon Sep 17 00:00:00 2001 From: Kevin Bost Date: Wed, 6 Mar 2024 22:31:44 -0800 Subject: [PATCH 3/3] Adding example of doing the test Rather than asserting on the style, it asserts on a set value from the style. --- .../WPF/DialogHosts/DialogHostTests.cs | 15 ++++++++------- MaterialDesignThemes.Wpf.Tests/DialogHostTests.cs | 1 - .../Themes/MaterialDesignTheme.DialogHost.xaml | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/MaterialDesignThemes.UITests/WPF/DialogHosts/DialogHostTests.cs b/MaterialDesignThemes.UITests/WPF/DialogHosts/DialogHostTests.cs index a21cadb3fc..50b53b8045 100644 --- a/MaterialDesignThemes.UITests/WPF/DialogHosts/DialogHostTests.cs +++ b/MaterialDesignThemes.UITests/WPF/DialogHosts/DialogHostTests.cs @@ -6,12 +6,8 @@ namespace MaterialDesignThemes.UITests.WPF.DialogHosts; -public class DialogHostTests : TestBase +public class DialogHostTests(ITestOutputHelper output) : TestBase(output) { - public DialogHostTests(ITestOutputHelper output) : base(output) - { - } - [Fact] public async Task OnOpenDialog_OverlayCoversContent() { @@ -491,7 +487,12 @@ public async Task DialogHost_DefaultStyleWithDialogCardStyleApplied_PassesStyleT IVisualElement grid = await LoadXaml($$""" - + + + + @@ -502,7 +503,7 @@ public async Task DialogHost_DefaultStyleWithDialogCardStyleApplied_PassesStyleT IVisualElement dialogHost = await grid.GetElement("DialogHost"); IVisualElement nestedCard = await dialogHost.GetElement("PART_PopupContentElement"); - // TODO: Assert the style on the nested card matches what is set in DialogHost.DialogCardStyle + Assert.Equal(new Thickness(42), await nestedCard.GetPadding()); recorder.Success(); } diff --git a/MaterialDesignThemes.Wpf.Tests/DialogHostTests.cs b/MaterialDesignThemes.Wpf.Tests/DialogHostTests.cs index cfc94767c2..b6cc44e812 100644 --- a/MaterialDesignThemes.Wpf.Tests/DialogHostTests.cs +++ b/MaterialDesignThemes.Wpf.Tests/DialogHostTests.cs @@ -1,7 +1,6 @@ using System.ComponentModel; using System.Threading; using System.Windows.Threading; -using Xunit; namespace MaterialDesignThemes.Wpf.Tests; diff --git a/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DialogHost.xaml b/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DialogHost.xaml index 5d91c37b4f..69d1a21449 100644 --- a/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DialogHost.xaml +++ b/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DialogHost.xaml @@ -158,7 +158,6 @@