In my situation, I need show available functions, disable functions of ContextMenu on selected ContentPane in menu of my Application.
How to know current ContentPane support what Contextmenu functions are available, disable?
Example:
- When ContentPane is docked in DoucmentHost, available ContextMenu functions of ContentPane is: "Close", "Close All But This", "Floating", "Dockable", "Hide", "New Horizontal Tab Group", "New Vertical Tab Group", disable functions of ContentPane is: "Auto Hide". If only one ContentPane in DocumentHost, "Close All But This", "New Horizontal Tab Group", "New Vertical Tab Group" is not available.
- When ContentPane is docked in SplitPane, available ContextMenu functions of ContentPane is: "Floating", "Tabbed Document", "Auto Hide", "Hide"
- When ContentPane is dockable floating, available ContextMenu functions of ContentPane is: "Floating", "Tabbed Document", "Hide", disable functions is "Auto Hide"
private void ContentPane_OptionsMenuOpening(object sender, Infragistics.Windows.DockManager.Events.PaneOptionsMenuOpeningEventArgs e) { ContentPane cp = e.OriginalSource as ContentPane; List<object> list = new List<object>(); foreach (var item in e.Items) { list.Add(item); } //When ContentPane is floating - disable "AutoHide" if (cp.PaneLocation == PaneLocation.Floating || cp.PaneLocation == PaneLocation.FloatingOnly) { int autoHideIndex = findItemIndex(list, "Auto Hide"); if (autoHideIndex != -1) { MenuItem autoHideItem = e.Items[autoHideIndex] as MenuItem; autoHideItem.IsEnabled = false; } } } private int findItemIndex(List<object> items, string header) { return items.FindIndex(item => item.GetType() == typeof(MenuItem) && (item as MenuItem).Header.Equals(header)); }
Hello Bozhidara Pachilova,
Thank you for your answer and sample. I think I got some ideas from your answer about check location of pane and find menu item index. It is good idea for me in case below request can not do.
I apologize, before my requestion may be not clearly.
Could you show me how to get IsEnable, IsVisible status of ContentPane’s context menu, please? or how to do that.
Example: I want create utility function as below and it will be call at anytime (not from OptionsMenuOpening event)
// input: contentPane: ContentPane owner of context menu need get status // input: context Menu Header. Exp: Floating, Hide, Auto Hide, ... // output: Context menu status (IsEnable,IsVisible) tuple result (bool, bool) getEnableDisableOfContextMenu(ContentPane contentPane, string menuHeader)
Background: I need show in application main menu items: floating, dockable, hide, auto hide, ..that have same visible, enable status of selected ContenPane's context menu items.
Hi Bozhidara Pachilova,
Thank you for your suggestion. Execute the ActivatePane command after Movexxx commands is OK.
Thank you again for all your assistance !
Sincerely,Cao Le
vm.curActivePane.ExecuteCommand(ContentPaneCommands.MoveToNewHorizontalGroup); vm.curActivePane.ExecuteCommand(ContentPaneCommands.ActivatePane);
Thank you very much for your help.
> Please, correct me if I am wrong.
Yes, that is my expect.
>I am afraid that accessing a pane’s Options Menu and its items would not be possible outside of the OptionsMenuOpening event, which is triggered when the Context Menu is opened through the UI. This means that while the proposed by you method sounds convenient, it will not be useful out of the OptionsMenuOpening as the Context Menu will be null, when not opened.
I understood. That mean I can not directly get status enable/visible of Options Menu outside outside of the OptionsMenuOpening event.
Thank you for your simple solution and sample. I checked it and it almost achieved my requirement. Based on that, I add behavior for 2 buttons Move To Previous Tab Group and Move To Next Tab Group.
Finally, I have a little trouble as below.
- Trouble: After clicked New to Vertical/Horizontal Tab Group or Move To Previous/Next Tab Group button, the current active Pane is not updated (ActivePaneChanged event not fired). Additionaly, I 've added ActiveDocumentChanged event but active pane is still not changed (ActiveDocumentChanged event not fired).
- Result: New to Vertical/Horizontal Tab Group or Move To Previous/Next Tab Group buttons status (disable/enable) not update after click that buttons. Only when direct click to select content pane, active pane is updated ok.
- Question: Could you show me how to fix above problem, please?
I attached updated sample source In the below. Please confirm it.
WPFContextMenu_update.zip
Hello Cao,
Thank you for following up and describing your requirement. I think I got the idea – you would like to have something like a ribbon over the XamDockManager with buttons, providing the same options as a Content Pane’s Options Menu and for the buttons’ actions to execute on the currently active pane. Additionally, you would like to have the buttons disabled/enabled, based on the current active pane’s location, similar to the default behavior of the Menu Items. Please, correct me if I am wrong.
I am afraid that accessing a pane’s Options Menu and its items would not be possible outside of the OptionsMenuOpening event, which is triggered when the Context Menu is opened through the UI. This means that while the proposed by you method sounds convenient, it will not be useful out of the OptionsMenuOpening as the Context Menu will be null, when not opened.
In the below attached sample, you will find a possible configuration that might work towards achieving your requirement. It involves storing the currently active pane in a View Model’s property of type Content Pane and some Boolean helper flags that are used for the buttons. The latter are defined in a StackPanel above the XamDockManager. Additionally, a BooleanToVisibilityConverter is used to control the visibility of the buttons based on the bound flags. As you can see, with the change of the active pane, the flags are updated and the buttons become enabled/disabled, similar to the context menu items. Finally, the corresponding ContentPane Commands are executed on the click of the corresponding button.
This solution is quite simplistic and please, keep in mind that it does not account for other configurations of the XamDockManager or other possible menu options. In case there are additional ones, you could add the functionality in a similar manner, if you choose to go down this road. Nevertheless, I hope it helps you with achieving your requirement.
Let me know if I may be of any further assistance.
Sincerely,Bozhidara PachilovaAssociate Software Developer
5672.WPFContextMenu.zip