PopupButton RoutedEvent not setting e.Handled=true correctly

Grids for WPF Forum

Posted 14 years ago by Mick
Version: 10.1.0523
Platform: .NET 3.5
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 14 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 (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.