views:

77

answers:

2

Hey. My WPF application is becoming a real pain. I have created a Window and would like to load another page when I click on a button. I assumed this would be straightforward, but it doesn't seem to be. I manage to load the other page by using this.content = new UserPage(). However, from this UserPage, I can't get back to my main window. I can't use this.content because the window can't be a child.

Therefore, I searched around and found out I should be using NavigationService to make things a lot easier. I tried to use NavigationService.GetNavigationService(this) but this didn't work as it always returned null. I figured it's because my main window is derived from Window and not NavigationWindow. Is there a way to convert my Window into a NavigationWindow without starting the project again? Whenever I create a new file, there's no NavigationWindow template - only Window, Page, User Control etc...

I tried manually replacing the XAML with NavigationWindow and it ran fine, but the NavigationService method still returned null. There was a bar at the top as well with back and forward arrow (both disabled), but I don't really need this. I would just like to use the Navigate() method so that I can easily switch between pages. Any ideas on what I can do?

Thanks for any help, this is driving me nuts! :)

+1  A: 

I tried manually replacing the XAML with NavigationWindow and it ran fine, but the NavigationService method still returned null

You don't need the NavigationService if your window is already a NavigationWindow. NavigationWindow has a Navigate method.

You can also use a standard Window and put a Frame control on it. It works roughly like a NavigationWindow, except that it's embedded in a window

Thomas Levesque
Thanks for the reply. How can I insert a frame within the window? I have a Grid (which contains the entire layout), but when I place a frame in the window, it replaces the grid. Is there a way to insert the frame into an existing window? Thanks again
Skoder
Put the Frame inside the Grid
Thomas Levesque
That works. I was trying to put my layout within the frame itself. Instead, I've just put the frame to the top of the visual tree and called its Navigate() method which seems to be working. Thanks for the help.
Skoder
A: 

I've done that but haven't been able to work out how to get the parent window reloaded from a vb.net statement in the page which is located in the frame. I have some code in the window_loaded function I wish to execute.

tombstarship
Are you using navigationservice.goback?
Skoder