Articles in this section
Category / Section

How to activate the child window on trying to re-add the same child in WPF DockingManager?

1 min read

As per implementation of WPF DockingManager, you cannot add the same element to the DockingManager which is already exist in DockingManager children collection. While adding same child element to the DockingManager, you can activate that element in DockingManager. The following code examples illustrate the same,

Mainwindow.xaml:

<Grid>
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="230"/>
    <ColumnDefinition Width="230"/>
    <ColumnDefinition Width="230"/>
  </Grid.ColumnDefinitions>
  <Button Content="SolutionExplorer" Click="Button_Click"/>
  <Button Content="ToolBox" Grid.Column="1" Click="Button_Click"/>
  <Button Content="Properties" Grid.Column="2" Click="Button_Click"/>
</Grid>
<syncfusion:DockingManager UseDocumentContainer="True" Name="docking"  Grid.Row="1">
  <ContentControl x:Name="SolutionExplorer" syncfusion:DockingManager.Header="Solution Explorer" syncfusion:DockingManager.State="Document"></ContentControl>
  <ContentControl x:Name="Properties" syncfusion:DockingManager.State="Document" syncfusion:DockingManager.Header="Properties"></ContentControl>
</syncfusion:DockingManager>    

Code to check whether the element is already in children collection of DockingManager or not:

We have iterated the child element of DockingManager and checked the existence of the element by its name. If the element is existing in DockingManager, activate the window using ActivateWindow method of DockingManager.

string name = (sender as Button).Content.ToString();                 
bool childexist = false;
foreach(FrameworkElement child in docking.Children)
{
  if(child.Name == name)
  {
    docking.ActivateWindow(child.Name);
    //docking.ActiveWindow = child;
    childexist = true;
    break;
  }
}
if(!childexist)
{
  var child = new ContentControl();
  child.Name = name;
  DockingManager.SetHeader(child, name);
  DockingManager.SetState(child as FrameworkElement, DockState.Document);
  docking.Children.Add(child as FrameworkElement);
}

View sample in GitHub.

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied