views:

33

answers:

1

I'm new to Silverlight and I'm having trouble understanding how to properly navigate between pages, especially when I need to pass data around.

Classic example: I have a list of People on one page, and when I click on a person in the datagrid I'd like to go to the details page and load that data. I need to pass the PersonId. More importantly, I need to know how to do this from the ViewModel.

It's easy to fire a command from the datagrid that is on the ViewModel, and the SelectedItem on the viewmodel is also bound and thus tracked, but then what? How do I get to the next page? I can't for the life of me figure this one out. This seems like it should be really easy, but so far it's been anything but easy.

A: 

The most basic thing to do would be to change what Application.Current.RootVisual is set to and set the appropriate DataContext. However it is much better to have some wrappers that set this up properly for you. For example in your custom view that you are navigating to you can have the view's constructor handle some of that logic for you in a nicer way. If you are using Prism then you are ultimately talking about modifying the shell, or a container within the shell.

stocherilac
Actually, once it is set, Application.Current.RootVisual cannot be changed, but the idea you are trying to transmit is exactly right.
Murven