Hi,@Leon NG. Welcome Microsoft Q&A.
If you want to nested Windows, this is not allowed. You could set UserControl
to SubWindow
instead of Window
Take the following example.
MainWindow.xaml:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ToolBar Grid.Row="0">
<ToolBar.Items>
<Button x:Name="AddSubWindow" Content=" AddSubWindow" Width="100" Height="50" Click="AddSubWindow_Click"/>
<Button x:Name="MoveOutSubWindow" Content=" AddSubWindow" Width="100" Height="50" Click="MoveOutSubWindow_Click" />
</ToolBar.Items>
</ToolBar>
<Border Name="MainBorder" Grid.Row="1">
<Grid x:Name="grid">
</Grid>
</Border>
</Grid>
MainWindow.xaml.cs:
SubWindow sw = new SubWindow();
private void AddSubWindow_Click(object sender, RoutedEventArgs e)
{
grid.Children.Add (sw);
}
private void MoveOutSubWindow_Click(object sender, RoutedEventArgs e)
{
grid.Children.Remove(sw);
}
SubWindow.xaml:
<Grid>
<Label Content="sub Window" FontSize="40" Name="label1" VerticalAlignment="Top" Width="254" />
</Grid>
The result:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.