CalciumFramework / Samples

Samples demonstrate how to use some of the features of Codon.
3 stars 2 forks source link

Passing parameters with NavigationService #3

Closed abrasat closed 7 years ago

abrasat commented 7 years ago

Is it possible to pass a parameter to the NavigationService ? Or what possibility is available to dynamically inject a view-model to a page reached by a call to the NavigateTo() method ? I need such functionality to open a detail view page, for instance when clicking on a row in a grid view. How can be passed to the detail view page the view model corresponding to the grid-view row that was selected ?

DVaughan commented 7 years ago

I'll look to add that capability for the next release.

For now though, you could register the view-model with the IoC container (perhaps with a string key). Dependency.Register<MyViewModel>(myViewModel, "TemporaryTask");

Then when you're done, unregister it by calling: Dependency.Register<MyViewModel>(null, "TemporaryTask");

abrasat commented 7 years ago

Thank you for the reply. I will take a look into the proposed workaround, I guess that I have to register the view model before calling the Navigate() method, and deregister it after calling the GoBack() method.

DVaughan commented 7 years ago

Please see the latest pre-release version 2.0.0-alpha. You can pass parameters by using the Navigate overload, like so: navigationService.Navigate(Routes.Page2, "Message from Page1ViewModel");

And then retrieve the value using: object argumentPassedFromPage1 = navigationService.NavigationArgument;

The signature of the IRoutingService.Register method has changed and now uses Action rather than Action. So this: routingService.RegisterPath(Routes.Page2, () => LaunchActivity<Page2Activity>(1)); becomes: routingService.RegisterPath(Routes.Page2, arg => LaunchActivity<Page2Activity>(1));

The branch for this work is named NavigationParameters.