PopupButton RoutedEvent not setting e.Handled=true correctly

Grids for WPF Forum

Posted 8 years ago by Mick
Version: 10.1.0523
Platform: Windows Forms Controls
Environment: Windows 7 (32-bit)
Avatar
Create a new WPF project and add the following code and call it right after the generated call to InitializeComponent():

public void CreatePopups()
{
    // Create a new window
    Window window = new Window { Width = 300, Height = 50 };

    // Set up the first level popup and hook up an event to notify us when it closes
    PopupButton level1 = new PopupButton { Label = "Click (Level 1)", VerticalAlignment = VerticalAlignment.Center };
    level1.PopupClosed += delegate { Debug.WriteLine("Level 1 Closed"); };

    // Set up the second level popup and hook up an event to notify us when it closes
    PopupButton level2 = new PopupButton { Label = "Click (Level 2)" };
    level2.PopupClosed += delegate { Debug.WriteLine("Level 2 Closed"); };

    // Nest the popups
    level1.PopupContent = level2;

    // Set some arbitrary content
    level2.PopupContent = new Button { Label = "Click the 'Level 2' button again" };

    window.Content = level1;

    // Show the window
    window.Show();
}
Steps to reproduce:
  • Set the focus to the newly created window.
  • Click the first button (Level 1) to show the second level.
  • Click the second button (Level 2) to show the third level.
  • Click the second button again (Level 2) to collapse the third level.
Result:
  • The PopupClosed event is fired for the first button when it should not be. Only the button at "Level 2" has been closed (this fires correctly). Check the Debug window for output.
In the mean time, I can assign an event handler to every one of my nested levels that sets e.Handled = true to avoid this bubbling behavior.

Mick

Comments (1)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hello,

The PopupClosed event is a routed event, so it is going to bubble up the visual tree. When you handle the PopupClosed event on the level1 PopupButton, you will also receive unhandled PopupClosed routed events from descendants.

You can tell which PopupButton was closed by checking the value of OriginalSource in the handler event args.

Please let us know if you have further questions.


Actipro Software Support

The latest build of this product (v2018.1 build 0675) was released 14 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.