Category / Section
How to customize the header in the TabListContextMenu of WPF DockingManager?
1 min read
The TabListContextMenuItemTemplate property of TabControlExt is used to define the template of items which is in TabListContextMenu of WPF DockingManager. For instance, we have retrieved the Header template of Document container and assigned the same to the template of TabListContextMenuItem. The following code demonstrate the same,
MainWindow.xaml:
<syncfusion:DockingManager x:Name="dockmgr" UseDocumentContainer="True" syncfusion:DocumentContainer.HeaderTemplate="{StaticResource DocumentTabHeaderItemTemplate}"> <ContentControl syncfusion:DockingManager.Header="Tab1" syncfusion:DockingManager.State="Document"/> <ContentControl syncfusion:DockingManager.Header="Tab2" syncfusion:DockingManager.State="Document"/> <ContentControl syncfusion:DockingManager.Header="Tab3" syncfusion:DockingManager.State="Document"/> <ContentControl syncfusion:DockingManager.Header="Tab4" syncfusion:DockingManager.State="Document"/> <ContentControl syncfusion:DockingManager.Header="Tab5" syncfusion:DockingManager.State="Document"/> </syncfusion:DockingManager>
DataTemplate for DocumentHeader
<DataTemplate x:Key="DocumentTabHeaderItemTemplate"> <DataTemplate.Resources> <Style TargetType="Image"> <Setter Property="Stretch" Value="Fill" /> <Setter Property="VerticalAlignment" Value="Center"/> </Style> </DataTemplate.Resources> <Grid Height="23"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" /> <ColumnDefinition /> </Grid.ColumnDefinitions> <Image Grid.Column="0" Width="15" Height="15" Stretch="Fill" Source="Image/docicon.png" /> <TextBlock Grid.Column="2" Margin="5 0" VerticalAlignment="Center" x:Name="headerTextBlock" Text ="{Binding}"/> </Grid> </DataTemplate>
MainWindow.cs
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); (dockmgr.DocContainer as DocumentContainer).Loaded += MainWindow_Loaded; } private void MainWindow_Loaded(object sender, RoutedEventArgs e) { TabControlExt tab = VisualUtils.FindDescendant(sender as Visual, typeof(DocumentTabControl)) as TabControlExt; if(tab != null) { tab.TabListContextMenuItemTemplate = DocumentContainer.GetHeaderTemplate(dockmgr); } } }