Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
160
How to know current ContentPane support what Contextmenu functions are available, disable?
posted

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"

Parents
  • 2680
    Offline posted
    Hello Cao,

     

    Thank you for posting to Infragistics Community.

     

    I have been looking into your question and created a small sample with a XamDockManager to demonstrate how the ContentPane’s MenuItems can be disabled, based on the pane’s location.

     

    To achieve this, my suggestion is to handle the ContentPane’s OptionsMenuOpening event. As you can observe, one handler can serve the events of multiple ContentPanes. The PaneOptionsMenuOpeningEventArgs object exposes the corresponding ContextMenu’s Items collection. Using it, the targeted menu item (the “Auto Hide”) can be retrieved and its IsEnabled property can be set to false. This is after checking whether the current pane’s PaneLocation is either “Floating” or “FloatingOnly”. In order not to hardcode the targeted menu item’s index, there is some additional logic concerned with creating a list of the items and finding the item with the particular Header using a helper function:

     

    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));
            }

     

    Regarding your requirement about disabling the "Close All But This", "New Horizontal Tab Group", "New Vertical Tab Group" menu items when there is a single pane within a Tab group, while this is possible using the approach from above, I determined that in fact those menu items are not displayed at all when there is a single pane within a Tab group. 
    In the ContentPane_OptionsMenuOpening handler in the sample, there is a commented code-snippet to demonstrate how this can be achieved, however, as stated, this code is redundant. Could you please, confirm that those items are not present in the context menu, when there is a single pane within the Tab Group on your side?

     

    Please, test the below attached sample on your side and in case of any other questions, please let me know.

     

    Sincerely,
    Bozhidara Pachilova
    Associate Software Developer
Reply Children