From 31659beec642b0519d7607cc1dfa6f6a99a66615 Mon Sep 17 00:00:00 2001 From: Corvin <43533385+corvinsz@users.noreply.github.com> Date: Thu, 8 Aug 2024 22:55:01 +0200 Subject: [PATCH] fixes #3643 - added ClickEvent handler for the PopupBoxContent in SplitButton and mark event as handled (#3646) --- src/MaterialDesignThemes.Wpf/SplitButton.cs | 15 ++++++- .../WPF/SplitButtons/SplitButtonTests.cs | 39 ++++++++++++++++++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/MaterialDesignThemes.Wpf/SplitButton.cs b/src/MaterialDesignThemes.Wpf/SplitButton.cs index ef7eb05cfe..d49dea0e19 100644 --- a/src/MaterialDesignThemes.Wpf/SplitButton.cs +++ b/src/MaterialDesignThemes.Wpf/SplitButton.cs @@ -17,7 +17,7 @@ static SplitButton() public PopupBoxPlacementMode PopupPlacementMode { - get => (PopupBoxPlacementMode) GetValue(PopupPlacementModeProperty); + get => (PopupBoxPlacementMode)GetValue(PopupPlacementModeProperty); set => SetValue(PopupPlacementModeProperty, value); } @@ -116,7 +116,7 @@ public DataTemplateSelector SplitContentTemplateSelector public Style ButtonStyle { - get => (Style) GetValue(ButtonStyleProperty); + get => (Style)GetValue(ButtonStyleProperty); set => SetValue(ButtonStyleProperty, value); } @@ -136,6 +136,17 @@ public override void OnApplyTemplate() WeakEventManager.AddHandler(_rightButton, nameof(Click), OpenPopupBox); } + if (_popupBox is not null) + { + _popupBox.RemoveHandler(ButtonBase.ClickEvent, (RoutedEventHandler)PopupContentClickedHandler); + _popupBox.AddHandler(ButtonBase.ClickEvent, (RoutedEventHandler)PopupContentClickedHandler); + } + + void PopupContentClickedHandler(object sender, RoutedEventArgs e) + { + e.Handled = true; + } + void OpenPopupBox(object? sender, RoutedEventArgs e) { if (_popupBox is not null) diff --git a/tests/MaterialDesignThemes.UITests/WPF/SplitButtons/SplitButtonTests.cs b/tests/MaterialDesignThemes.UITests/WPF/SplitButtons/SplitButtonTests.cs index e8ba3c7634..48a818cc56 100644 --- a/tests/MaterialDesignThemes.UITests/WPF/SplitButtons/SplitButtonTests.cs +++ b/tests/MaterialDesignThemes.UITests/WPF/SplitButtons/SplitButtonTests.cs @@ -1,6 +1,6 @@ using MaterialDesignThemes.UITests.Samples.SplitButton; -[assembly:GenerateHelpers(typeof(SplitButtonWithCommandBinding))] +[assembly: GenerateHelpers(typeof(SplitButtonWithCommandBinding))] namespace MaterialDesignThemes.UITests.WPF.SplitButtons; @@ -152,4 +152,41 @@ public async Task SplitButton_CommandCanExecuteFalse_DisablesButton() recorder.Success(); } + + [Fact] + public async Task SplitButton_ClickingPopupContent_DoesNotExecuteSplitButtonClick() + { + await using var recorder = new TestRecorder(App); + + //Arrange + IVisualElement splitButton = await LoadXaml(""" + + +