When the user right clicks the header or tabheader of a contentpane I'd like to show a context menu. One of the items on the context menu would be to edit the text of the header or tabheader. I created a datatemplate containing a text block and added a context menu to the text block but when I right clicked on the text block the context menu did not appear.
DataTemplate headerTemplate = new DataTemplate();
headerTemplate.DataType = typeof(ContentPane);
FrameworkElementFactory headerTextBlock = new FrameworkElementFactory(typeof(TextBlock));
headerTextBlock.SetValue(TextBlock.TextProperty, "My Text");
ContextMenu cm = new System.Windows.Controls.ContextMenu();MenuItem mi = new MenuItem();
mi.Header = "Edit Tab Name"
mi.Command = ...
cm.Items.Add(mi);
headerTextBlock.SetValue(TextBlock.ContextMenuProperty, cm);
headerTemplate.VisualTree = headerTextBlock;
headerTemplate.Seal();
e.NewPane.TabHeaderTemplate = headerTemplate;
The above did not work - the context menu did not appear when the text block was right clicked.
What's the best way to get context menu for the header area?
Hello,
Thank you for your post. I have been looking into your question and I can suggest using the OptionsMenuOpening event of the ContentPane. The event is fired when you are opening the ContextMenu for the ContentPane headers and you can edit the items of that menu in the event handler. You can use the e.Items form the event args in order to add or remove items. I have created a sample application for you, that shows how you can add an extra item to that menu.
Please let me know if you need any further assistance on the matter.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
I am just checking if you require any further assistance on the matter.
I'm afraid your reply isn't related to what I was trying to ask so let me try to ask again. In addition, I'm using the xpf family of dlls and not the wpf family should that distinction matter in your reply.
When a user right clicks on a content pane either in the preview right click event or in the PaneOptionsMenuOpening event how can I tell whether the user right clicked on the:
1. contentpane header
_or_
2. whether they right clicked somewhere in the body of the contentpane.
I'm trying to avoid having to hard code a height in the y-axis direction for the height of the header as header content and font size may vary. I dont see amy thing in the PaneOptionsMenuOpeningEventArgs that would help me tell where the user originally clicked
Thank you for your reply. I have been looking into it and regarding your first question, I am not completely sure which assemblies are you using. Would you please provide me with more detailed description of what you are referring to by “xpf family of dlls”, since Infragistics does not provide “xpf” assemblies for WPF?
Regarding your second question, the ContextMenu, that you are referring to is appearing only when you are clicking on the header of the ContentPane. When you are right clicking on the content of a ContentPane, by default, no ContextMenu is appearing. Would you please clarify, whether you are referring to the pane’s options menu, that contains the following items by default:
Or you are referring to some custom menu that you have added to the XamDockManager’s ContentPanes?
Looking forward to hearing from you.
Krasmir was offering a solution that would best provide the ability to expose your menu items because it would be mixed in with our menu items so you wouldn't lose the existing menu items, you wouldn't have to worry about how the end user chose to show the menu and you wouldn't have to worry about suppressing/ignoring a contextmenu being shown as a result of a right click/shift-f10/etc within the content of the ContentPane. With regards to height evaluation if you are dealing with something like PreviewMouseRightButtonUp then you would probably be better off starting with the e.OriginalSource and walking up the logical/visual tree to see if you are within a particular element. e.g.
var dp = e.OriginalSource as DependencyObject;while (dp is ContentElement) dp = LogicalTreeHelper.GetParent(dp);while (dp != null){ if (dp is PaneTabItem) { // the event happened within the pane tab break; } dp = VisualTreeHelper.GetParent(dp);}
We have reached an impass. I ask about determining the height of the tabheader so I can use mouse positition in a right button event and you insist I should use OptionsMenuOpening. Fortunately I found a way to make a reasonable estimate of the tabheight based on the actualheight of the content I put into the tabheader so I'm using that. I do not wish any further assistance.
Thank you for your reply and the clarification on the matter. I have been looking into the functionality that you have described and if you wish to display context menu, only on the headers of the ContentPanes, I can suggest using the approach I have originally suggested: using the OptionsMenuOpening event of the ContentPane and using the options menu of the ContentPane. By default, if you set the ContextMenu property of the ContentPane, the context menu will appear only on the content of the ContentPane, since the header is using the options menu, to which I am referring. Using the OptionsMenuOpening event of the ContentPane, you can clear the default items of the menu and add the items you wish. Also the options menu is appearing only on the header of the ContentPane. I have modified the sample application that I have originally attached, in order to show how you can clear the items of the menu and add only the items that you are creating.
My mistake about the dll names. We are using InfragisticsWPF4.Controls.xxx.v12.1.dll and InfragisticsWPF4.DocManager.V12.1.dll. I was looking in the wrong folder, my bad.
I added a very simple context menu to the contentpane:
In the xamDockManager1InitializePaneContent event a simplified version of my code is:
ContextMenu cm = new ContextMenu();
MenuItem mi = new MenuItem();
Mi.Header ="Edit Graph Name";
cm.Items.Add(mi)'
e.NewPane.ContextMenu = cm;
Now when ever I right click either on the body of the contentpane or on the tabHeader of the contentpane my context menu appears.
I would like the context menu to only appear if the use clicks on the tabheader portion of the contentpane. My original thought was to use the PreviewMouseRightButtonUp event to determine if the click was on the tabheader or on the body of the content pane. I can call the getposition() method of the MouseButtonEventHandler but I need a reliable way to know if the position returned is in the tabheader or on the body of the content pane.