System.InvalidOperationException: 'Window must be the root of the tree. Cannot add Window as a child of Visual.'

  • Thread starter Thread starter reecw
  • Start date Start date
R

reecw

Guest
Hi everyone,

I'm currently working on a project that needs to navigate between a Window and a Page. I've managed to navigate between a Window to a Page using the following code:


public void AboutButton_Click(object sender, RoutedEventArgs e)
{
About about = new About();
this.Content = about.Content;

}

However, when I try to navigate back to my Window using this code:

public void HomeButton_Click(object sender, RoutedEventArgs e)
{
MainWindow home = new MainWindow();
this.Content = home;


}

It displays the error that is: System.InvalidOperationException: 'Window must be the root of the tree. Cannot add Window as a child of Visual.' I understand now that you cannot navigate back to a Window using a Page, however is there a workaround to this? Something I can implement without too much redesigning of my entire code? Please let me know if you need anymore information!

Reece

Continue reading...
 

Similar threads

D
Replies
0
Views
150
dabina2018
D
D
Replies
0
Views
111
DenisAndreevich
D
Back
Top