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?

 

Parents
  • 30945
    Offline posted

    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

    ContentTabHeaderContextMenu.zip
Reply Children