Category / Section
How to disable the element which state is document in WPF DockingManager?
1 min read
By default, child element of DockingManager (which has state as Document) will be added as content of TabItemExt in DocumentTabControl. To disable the document child element of WPF DockingManager, we must retrieve the TabItemExt element from DocumentTabControl and set IsEnabled as false to the retrieved element. For instance, we have disabled all the items in the DocumentTabControl, except SelectedItem. The following code demonstrate the same,
MainWindow.xaml:
<syncfusion:DockingManager x:Name="dockingManager" Grid.Row="1" ShowTabItemContextMenu="False" ShowTabListContextMenu="False" IsTDIDragDropEnabled="False" EnableMouseHoverBackground="False" IsTabPreviewEnabled="False" UseDocumentContainer="True"> <!-- Sample Window --> <ContentControl syncfusion:DockingManager.State="Document" syncfusion:DockingManager.Header="TAB_1" x:Name="tab1" syncfusion:DockingManager.DocumentTabOrderIndex="1" /> <ContentControl syncfusion:DockingManager.State="Document" syncfusion:DockingManager.Header="TAB_2" x:Name="tab2" syncfusion:DockingManager.DocumentTabOrderIndex="2" /> <ContentControl syncfusion:DockingManager.State="Document" syncfusion:DockingManager.Header="TAB_3" x:Name="tab3" syncfusion:DockingManager.DocumentTabOrderIndex="3" /> </syncfusion:DockingManager>
Code to disable the child element of DockingManager:
private void DisableOtherTabs(string nameForFind, bool value) { foreach (TabItemExt element in documenttab.Items) { if (nameForFind != element.Header.ToString()) { element.IsEnabled = value; } } }
MainWindow.cs:
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); (dockingManager.DocContainer as DocumentContainer).Loaded += MainWindow_Loaded; } DocumentTabControl documenttab = null; private void MainWindow_Loaded(object sender, RoutedEventArgs e) { documenttab = VisualUtils.FindDescendant(sender as Visual, typeof(DocumentTabControl)) as DocumentTabControl; } private void btnDisable_Click(object sender, RoutedEventArgs e) { string header = (documenttab.SelectedItem as TabItemExt).Header.ToString(); DisableOtherTabs(header, false); } private void DisableOtherTabs(string nameForFind, bool value) { foreach (TabItemExt element in documenttab.Items) { if (nameForFind != element.Header.ToString()) { element.IsEnabled = value; } } } private void Button_Click(object sender, RoutedEventArgs e) { string header = (documenttab.SelectedItem as TabItemExt).Header.ToString(); DisableOtherTabs(header, true); } }