NavigationWindow - Where is it?

3k views Asked by At

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! :)

3

There are 3 answers

6
Thomas Levesque On BEST ANSWER

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

0
Quark Soup On

Skoder,

I'm not really sure what you are trying to do, but I'll see if I can help. First, it sounds like you want a NavigationWindow. If you only want one Page in your application, then your first approach will work but the minute you talk about more than one page and wanting to move from one page to another, you are talking about a NavigationWindow.

Second, once you choose a navigation window, the XAML should be straight forward, just replace Window with NavigationWindow and you should be good to go except you need to realize now that you will no longer directly control the content of the window. Instead the built-in NavigationService will handle this. Oh, and you don't need to create an explicit NavigationService as the class already provides one. You simply need to navigate:

 this.Navigate(new Url("pack://aplication:,,,/MyAssembly,component/MyPage.xaml", UriKind.Absolute));

alternatively, use can use XAML:

Source = "pack://aplication:,,,/MyAssembly,component/MyPage.xaml"

At this point, you will need some interface to allow your users to get from one page to the next (e.g. Breadcrumb control or TreeView), but once they are there the built-in travel control will allow you to navigate through the Journal that is maintained automatically for you. That is, most of the basic work of navigating is done for you, you just need to figure out how the user navigates forward to some content.

But at this point, things can get pretty strange. I ran into this myself. Since you can't add a grid or any other content explicity to the frame, you need to alter the template of the NavigationWindow in order to add the extra controls that make up a normal application. Things such as Menus and Toolbars are not part of the standard WPF NavigationWindow.

Forgive this shameless bit of self-promotion, but I've built a product because I ran into these limitations and there wasn't anything available on the market. You can take a look at the demo at:

http://www.teraque.com/products/explorer-chrome-suite/

It was designed to be the professional version of the WPF NavigationControl that Microsoft gives away for free. Take a look at the demo, if you don't want to purchase the suite, I'd be happy to give away pointers if this is the direction you want to take your application.

Sincerely,

Donald Roy Airey

[email protected]

1
tombstarship On

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.