Category / Section
How to hide specific menu items in default context menu of the TabItemExt in WPF DockingManager?
2 mins read
You can hide the selected context menu according to the requirement in WPF DockingManager. The following screenshot shows the default context menu of the document child.
For instance, to show only the close context menu of the document child in the DockingManager, you need to hide all the other default context menu items. This can be done by using the Boolean property of the DockingManager that has a naming convention, Show + Nameof theContextMenuItem. By disabling this property, you can hide the unnecessary context menu items.
The following code example demonstrates the same.
XAML
<Window x:Class="TabControl.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:syncfusion="http://schemas.syncfusion.com/wpf" xmlns:shared="clr-namespace:Syncfusion.Windows.Shared;assembly=Syncfusion.Shared.WPF" xmlns:local="clr-namespace:Syncfusion.Windows.Tools.Controls;assembly=Syncfusion.Tools.Wpf" Title="MainWindow" Height="350" Width="525"> <Grid x:Name="Grid1"> <syncfusion:DockingManager x:Name="DockingManager1" UseDocumentContainer="True" ContainerMode="TDI" > <ContentControl x:Name="Content1" syncfusion:DockingManager.Header="Tab1" syncfusion:DockingManager.State="Document" syncfusion:DockingManager.ShowCloseAllButThisMenuItem="False" syncfusion:DockingManager.ShowCloseAllMenuItem="False" syncfusion:DockingManager.ShowFloatingMenuItem="False" syncfusion:DockingManager.ShowDockableMenuItem="False" syncfusion:DockingManager.ShowTabbedMenuItem="False" syncfusion:DockingManager.ShowVerticalTabGroupMenuItem="False" syncfusion:DockingManager.ShowHorizontalTabGroupMenuItem="False" syncfusion:DockingManager.CanDock="False" syncfusion:DockingManager.ShowDocumentMenuItem="False" </ContentControl> <ContentControl x:Name="Content2" syncfusion:DockingManager.Header="Tab2" syncfusion:DockingManager.State="Document" ></ContentControl> </syncfusion:DockingManager> </Grid> </Window>
C#
using Syncfusion.Windows.Tools.Controls; using Syncfusion.Windows.Tools.Controls; namespace TabControl { /// <summary> /// Interaction logic for MainWindow.xaml. /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); DockingManager DockingManager1 = new DockingManager(); DockingManager1.UseDocumentContainer = true; ContentControl Content1 = new ContentControl(); DockingManager.SetHeader(Content1, "Tab1"); DockingManager.SetState(Content1, DockState.Document); DockingManager.SetShowCloseAllMenuItem(Content1, false); DockingManager.SetShowCloseAllButThisMenuItem(Content1, false); DockingManager.SetShowDockableMenuItem(Content1, false); DockingManager.SetShowFloatingMenuItem(Content1, false); DockingManager.SetShowTabbedMenuItem(Content1, false); DockingManager.SetShowDocumentMenuItem(Content1, false); DockingManager.SetShowHorizontalTabGroupMenuItem(Content1, false); DockingManager.SetShowVerticalTabGroupMenuItem(Content1, false); DockingManager1.Children.Add(Content1); ContentControl Content2 = new ContentControl(); DockingManager.SetHeader(Content2, "Tab2"); DockingManager.SetState(Content2, DockState.Document); DockingManager1.Children.Add(Content2); Grid1.Children.Add(DockingManager1); } } }
The following screenshot shows only the close context menu item in the document child of the DockingManager.