We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Add menu item to tab context menu

Thread ID:

Created:

Updated:

Platform:

Replies:

144155 Apr 22,2019 08:32 PM UTC Apr 23,2019 12:13 PM UTC WPF 4
loading
Tags: DocumentContainer
Adam
Asked On April 22, 2019 08:32 PM UTC

Hi, when I right click on tab, I can see default context menu like: Close, Close all, Close all but this etc.
I was wondering, how can I add my custom menu items to the default one?

Jagadeesan Pichaimuthu [Syncfusion]
Replied On April 23, 2019 06:51 AM UTC

Hi Adam, 

Thanks for using Syncfusion products. 

You can able to add the custom context menu items while loading the document container. Please find the below code snippet where the new menu item is added with existing items. 

documentContainer.Loaded += DocumentContainer_Loaded; 
 
private void DocumentContainer_Loaded(object sender, RoutedEventArgs e) 
{ 
    DocumentTabControl tabControl = VisualUtils.FindDescendant(sender as Visual, typeof(DocumentTabControl)) as DocumentTabControl; 
    foreach (var item in tabControl.Items) 
    { 
        if (item is TabItemExt) 
        { 
            TabItemExt tabItem = item as TabItemExt; 
            CustomMenuItem menuItem = new CustomMenuItem(); 
            menuItem.Header = "CustomMenuItem"; 
            if (tabItem != null && tabItem.Header.ToString() == "Integration") 
            { 
                tabItem.ContextMenuItems.Add(menuItem); 
            } 
        } 
    } 
} 



Please find the sample from below location for your reference. 



 


Let us know whether this helps also if you need any further assistance on this. 

Regards, 
Jagadeesan

Adam
Replied On April 23, 2019 11:32 AM UTC

It doesn't work the way I thought.
Menu is created only for statically created tabs in XAML.
But I create also tabs dynamically in code, and those tabs don't get it my custom menu.

This is how I create the tabs:

DocumentControl dc = new DocumentControl(viewModel.Localizer);
dc.DataContext = docViewModel;
docContainer.Items.Add(dc);
DocumentContainer.SetHeader(dc, docViewModel.Document);

And now the question is - how to apply my custom menu to dynamically created tabs?

Adam
Replied On April 23, 2019 12:05 PM UTC

OK, with your code I was able to resolve this:

DocumentControl dc = new DocumentControl(viewModel.Localizer);
dc.DataContext = docViewModel;
docContainer.Items.Add(dc);
DocumentContainer.SetHeader(dc, docViewModel.Document);

AddMenusToDocumentTab(tabControl.Items[tabControl.Items.Count -1] as TabItemExt);

You just have to make sure that you add your tabs at the end of the list.
And AddMenus... is simple as:


CustomMenuItem result = new CustomMenuItem();
result.Header = name;
result.Command = cmdToExecute;

tabItem.ContextMenuItems.Add(result);


Jagadeesan Pichaimuthu [Syncfusion]
Replied On April 23, 2019 12:13 PM UTC

Hi Adam, 
 
Thanks for your update. 
 
We are glad to know that the provided solution worked at your end. Please let us know if you have any further queries on this. We are happy to help you. 
 
Regards, 
Jagadeesan 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon