Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
This error occurs: - System.InvalidOperationException: 'Window must be the root of the tree. Cannot add Window as a child of Visual.' I want to open another WPF window inside the stack panel. If WPF window can't open, then give some other good option. 


What I have tried:

C#
private ObjectPlacement objectPlacement;



private void Button_Click_4(object sender, RoutedEventArgs e)
 {
    ObjectPlacement W = new ObjectPlacement();// other WPF window
    settingpanel.Children.Add(objectPlacement);//setting panel is stack panel.
    W.Show();
 }
Posted
Updated 24-Feb-23 1:30am
Comments
[no name] 23-Jan-23 4:34am    
You can't; the closest thing is a user control (that looks like a window).

WPF does not have Windforms MDI. You can use a Frame with Pages or ContentControl with UserControls (easiest).

Here, watch this. This will show you how to do what you want: WPF Switching Views With Navigation Using MVVM And Dependency Injection - YouTube[^]
 
Share this answer
 
private void Object_placement_Click(object sender, RoutedEventArgs e)
       {
           settingpanel.Children.Clear();
           UserControl1 newFormControl = new UserControl1();
           settingpanel.Children.Add(newFormControl);
       }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900