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