I have a docking manager with a custom context menu. The ContextMenu is being brought up when right-clicking the header of the content, and when clicking on the context menu button. However, I have the following problem: When right-clicking, the ContextMenuOpening event gets fired when the menu is opened, then the ContextMenuClosing event gets fired when the menu is closed. However, when clicking on the context menu button, the ContextMenuOpening event does not get fired, and instead the BeforeContextMenuOpen event gets fired. Additionally, when the context menu closes when in this scenario, the ContextMenuClosing event does not get fired either. Why are there 2 different opening events that get fired instead of just one, and why is there no closing event for when the context menu is brought up from the menu button?
Hi Josepth Badrouk,
Thank you for your detailed observation regarding the behavior of the ContextMenuOpening and ContextMenuClosing events in the DockingManager's custom context menu.
We would like to inform you of the following regarding your query:
When the context menu is opened via right-click, WPF’s framework-level ContextMenuOpening and ContextMenuClosing events are triggered as expected.
However, when using the context menu button (ToggleButton), the menu is opened programmatically, not by the WPF framework. In this case:
ContextMenuOpening and ContextMenuClosing events do not fire.
Only our internal BeforeContextMenuOpen event is triggered.
Similarly, clicking outside to close the popup also does not trigger ContextMenuClosing.
To reliably handle Opened and Closed events regardless of how the context menu is opened, we recommend using EventManager.RegisterClassHandler() to subscribe to these events. This ensures the events are triggered consistently, including for button-based interactions.
We’ve attached a sample demonstrating this implementation for your reference.
Additionally, we’ve logged a feature request to providing closing event support specifically for cases where the context menu is opened or closed via a button.
We will implement this feature in any of our upcoming releases.
At the planning stage for every release cycle, we review all open features and identify features for implementation based on specific parameters including product vision, technological feasibility, and customer interest. We will let you know when this feature is implemented. We appreciate your patience until then.
Thank you for requesting this feature and helping us define it. We are always trying to make our products better and feature requests like yours are a key part of our product growth efforts.
Feedback link: Implement CloseContextMenuCommand support in CustomContextMenu in WPF | Feedback Portal
If you have any more specifications/suggestions for the feature request, you can add them as a comment in the portal and cast your vote to make it count.
Regards,
Sekar Sivalingam
Thank you for the provided workaround, however there is a strange behavior with this solution. When clicking the context menu button (ToggleButton), the opened event is fired. When clicking the context menu button of another menu without closing the one currently opened, the opened event is fired before the closed event, causing inconsistent behaviors. I've attached a video illustrating the problem.
Hi Josepth Badrouk,
Thank you for sharing your observation and the video demonstration regarding the event order when switching between context menu buttons.
We’ve thoroughly tested this scenario on our end using the recommended workaround. However, we were not able to reproduce the behavior where the Opened event is triggered before the Closed event.
To better understand the scenario and provide an accurate resolution, could you please share a reproducible sample of your application if possible? This will help us analyze the exact conditions under which the behavior occurs.
Additionally, we've attached our testing video demonstration showing the expected event sequence for your reference.
We appreciate your continued cooperation and look forward to your sample so we can assist you further.
Regards,
Sekar Sivalingam
I am able to reproduce it by both right-clicking the header of another window and by also clicking the context menu button. You have to click it right away without long-pressing the button or the mouse right button for this to occur.
Hi Josepth Badrouk,
We would like to inform you that this is the expected behavior, and we have validated it using Microsoft WPF controls as well.
We tested the same scenario using the default Microsoft TabControl with a ContextMenu. We observed that the Opened and Closed events are triggered in the expected order when the context menu is opened using the context menu button.
However, the inconsistency in the event order occurs only when the context menu is opened via right-click on the header. This behavior is also reproduced in the Microsoft TabControl, confirming that it is consistent with WPF framework behavior and not specific to the Syncfusion DockingManager or CustomContextMenu.
We've attached our testing sample and video demonstration for your reference. Please let us know if you have any further questions.
Regards,
Sekar Sivalingam