0

I have no idea why this is so hard for me to find an answer to. Essentially, just like in a windows form, i create a new object of a page, and then display it.

However you cant do that in WPF, so instead, I set the content of the main page, to that of the created object.

This all works great, but when i want to shut the newly opened page, I cannot. I obviously cant do anything like this.close. And I have no reference to the MainWindow, so I cannot re-set the content?

Please help, I am VERY confused!

More Details...

Sorry, Its not the most clear question. In my mainWindow, I have

Page1 mainMenu = new Page1();

this.Content = mainMenu;

This brings up my new page, like a new window, but without actually loading a new window, which is actually great!

However, my current page now has the content of Page1. So its running the code and displaying the content from Page1.

In page one, how do I return the content back to MainWindow? I have tried many things which all essentially get the error -

"Logical tree depth exceeded while traversing the tree. This could indicate a cycle in the tree."

MichaelMcCabe
  • 523
  • 4
  • 15
  • 33
  • It's not clear exactly what you're trying to do - maybe if you posted some code (or pseudo-code) for how you'd do this in Windows Forms, someone can help you do the same thing in WPF. – E.Z. Hart Jul 28 '11 at 16:12

4 Answers4

2

"Essentially, just like in a windows form, i create a new object of a page, and then display it. However you cant do that in WPF, so instead.." That statement / question is vague. You do know you can open the page in a NavigationWindow?

    NavigationWindow win = new NavigationWindow();
    win.Content = new pageWFbchAdmin();
    win.Show();
paparazzo
  • 44,497
  • 23
  • 105
  • 176
1

Page is generally used in a Frame or NavigationWindow. There in, you have the possibility to navigate between pages.

Your code has replaced the content of the window and there is no navigation functionality in window. What you can do is open a new Window and close the current, or set other content to the Content-property of your window.

IMO you are mixing different UI technoligies. If you want to make a browser-like application, look at the NavigationWindow or the Frame-class. Otherwise, probably it's better not to use the Page-object but UserControls. Maybe this link will help you.

HCL
  • 36,053
  • 27
  • 163
  • 213
0

I may have misunderstood what you're trying to do but I'm wondering if what you really want is to make your Page a Window and then show it using the Window.ShowDialog method.

That way it'll behave like a modal dialog which sounds a bit like what you describe at the start of the question.

Alternatively, instead of replacing the content of the main window, you could try putting both the main content and the page content in the MainWindow...in separate panels on top of each other and then toggle the visibility of each panel to show/hide the required content.

IanR
  • 4,703
  • 3
  • 29
  • 27
0

Page may not have a Close method but NavigationWindow has a Close method. A Page is content (not a visual host).

paparazzo
  • 44,497
  • 23
  • 105
  • 176