How to navigate in Silverlight 4.0 using MVVM?

I'm new to Silverlight, and it's hard for me to figure out how to navigate between pages correctly, especially when I need to transfer data.

A classic example: I have a list of people on one page, and when I click on a person in a datagrid, I would like to go to the details page and download this data. I need to pass PersonId. More importantly, I need to know how to do this from ViewModel.

It's easy to run a command from a datagrid that is in the ViewModel, and the SelectedItem on the viewmodel is also linked and thus tracked, but what then? How to go to the next page? I can’t let life show me. It sounds like it should be very simple, but so far it has been easy.

+3
source share
2 answers

The most basic thing to do is change the installation method Application.Current.RootVisualand install the appropriate one DataContext. However, it is much better to have some wrappers that have configured this correctly for you. For example, in your custom view, which you can go to, you can better handle the view constructor with some logic for you. If you use Prism, then you are ultimately talking about changing the shell or container inside the shell.

0
source

SelectedItemChanged ViewModel "SelectedItem" , . ViewModel Singleton. DataContext ViewModel, SelectedItem , .

, , , , SelectedItem DataGrid ViewModel .

0

Source: https://habr.com/ru/post/1771986/


All Articles