Category / Section
How to programatically dock the auto-hidden child by clicking the SidePanel in WPF DockingManager?
1 min read
As per the behavior of WPF DockingManager, the Auto hidden dock child will expand / hide when mouse hover on AutoHideSidePanel and the “Auto hidden dock child state can be changed to Dock state directly” on clicking anywhere in AutoHideTabItem by handling its SidePanel MouseDown event and using SetDock function in DockingManager.
XAML
<syncfusion:DockingManager x:Name="DockingManager1"> <ContentControl x:Name="leftpanel" syncfusion:DockingManager.Header="Docking Left" syncfusion:DockingManager.SideInDockedMode= "Left" /> <ContentControl x:Name="rightpanel" syncfusion:DockingManager.Header="Docking Right" syncfusion:DockingManager.SideInDockedMode= "Right"/> <ContentControl x:Name="bottompanel" syncfusion:DockingManager.Header="Docking Bottom" syncfusion:DockingManager.SideInDockedMode="Bottom" /> </syncfusion:DockingManager>
C#
/// <summary> /// This event will raise when DockingManager is loaded /// </summary> void DockingManager1_Loaded(object sender, RoutedEventArgs e) { foreach (SidePanel panel in VisualUtils.EnumChildrenOfType(DockingManager1, typeof(SidePanel))) { if (panel.Name == "PART_LeftPanel") { panel.PreviewMouseDown += Panel_PreviewMouseDown; } else if (panel.Name == "PART_RightPanel") { panel.PreviewMouseDown += Panel_PreviewMouseDown; } else if(panel.Name == "PART_BottomPanel") { panel.PreviewMouseDown += Panel_PreviewMouseDown; } } } /// <summary> /// This event will be raised when Mouse button is pressed. /// </summary> private void Panel_PreviewMouseDown(object sender, MouseButtonEventArgs e) { panelname = (sender as SidePanel).Name; Point point = new Point(); if (e is MouseEventArgs) point = (e as MouseEventArgs).GetPosition(this); HitTestResult hitTest = VisualTreeHelper.HitTest(this, point); if (hitTest != null) { FrameworkElement visualHit = hitTest.VisualHit as FrameworkElement; if (null != visualHit) { DependencyObject templatedParent = visualHit.TemplatedParent; if (null != templatedParent && (templatedParent is ContentPresenter) || (templatedParent is TabItem)) { switch(panelname) { case "PART_LeftPanel": DockingManager.SetState(this.leftpanel, DockState.Dock); break; case "PART_RightPanel": DockingManager.SetState(this.rightpanel, DockState.Dock); break; case "PART_BottomPanel": DockingManager.SetState(this.bottompanel, DockState.Dock); break; } } } } }