Navigation - retrieving user input from Regions

Viewed 34

I know the way to pass in parameters to region that are being navigated to.

My question is: what is the preferred way in the parent viewmodel to access user input values from the child regions that are being navigated in the UI?

2 Answers

If you need Prism's navigation, there are the usual suspects: a built-in service (e.g. IEventAggregator), a custom service (e.g. MyInputBroker) or an external service (e.g. a REST-Api where the children PUT to and the parent GETs from).

If you can go view model-first, it's far easier and the parent just asks its children or it has provided them with callback.

The later option is theoretically possibly even with OnNavigatedTo (given the parent view model triggers the navigation): you put the parent view model in the NavigationParameters.

Seems that one way would be to Use a DataModel class passed in to the Regions as parameter through the OnNavigatedTo() and bind the Region's fields to the members of this DataModel.

In .net Classes being passed by reference, changes in the child-region made to this DataModel will be available in the parent through the object passed in to the regions.

I am interested to know if there is something better than this that I could do.

Related