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
100
Context menu for tabheader and header of a content pane
posted

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?