Skip to content
Merged
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
15 changes: 13 additions & 2 deletions src/MaterialDesignThemes.Wpf/SplitButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static SplitButton()

public PopupBoxPlacementMode PopupPlacementMode
{
get => (PopupBoxPlacementMode) GetValue(PopupPlacementModeProperty);
get => (PopupBoxPlacementMode)GetValue(PopupPlacementModeProperty);
set => SetValue(PopupPlacementModeProperty, value);
}

Expand Down Expand Up @@ -116,7 +116,7 @@ public DataTemplateSelector SplitContentTemplateSelector

public Style ButtonStyle
{
get => (Style) GetValue(ButtonStyleProperty);
get => (Style)GetValue(ButtonStyleProperty);
set => SetValue(ButtonStyleProperty, value);
}

Expand All @@ -136,6 +136,17 @@ public override void OnApplyTemplate()
WeakEventManager<Button, RoutedEventArgs>.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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using MaterialDesignThemes.UITests.Samples.SplitButton;

[assembly:GenerateHelpers(typeof(SplitButtonWithCommandBinding))]
[assembly: GenerateHelpers(typeof(SplitButtonWithCommandBinding))]

namespace MaterialDesignThemes.UITests.WPF.SplitButtons;

Expand Down Expand Up @@ -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> splitButton = await LoadXaml<SplitButton>("""
<materialDesign:SplitButton VerticalAlignment="Bottom"
Content="Split Button"
Style="{StaticResource MaterialDesignRaisedLightSplitButton}">
<materialDesign:SplitButton.PopupContent>
<Button x:Name="PopupContent" />
</materialDesign:SplitButton.PopupContent>
</materialDesign:SplitButton>
""");

IVisualElement<PopupBox> popupBox = await splitButton.GetElement<PopupBox>();
IVisualElement<Button> popupContent = await splitButton.GetElement<Button>("PopupContent");

IEventRegistration splitButtonClickEvent = await splitButton.RegisterForEvent(ButtonBase.ClickEvent.Name);
IEventRegistration popupContentClickEvent = await popupContent.RegisterForEvent(ButtonBase.ClickEvent.Name);

//Act
await popupBox.LeftClick();
//NB: give the popup some time to show
await Wait.For(async () => await popupContent.GetIsVisible());
await Wait.For(async () => await popupContent.GetActualHeight() > 10);
await popupContent.LeftClick();
await Task.Delay(50);

// Assert
Assert.Empty(await splitButtonClickEvent.GetInvocations());
Assert.Single(await popupContentClickEvent.GetInvocations());

recorder.Success();
}
}