Daniel Hindrikes
Developer and architect with focus on mobile- and cloud solutions!
Developer and architect with focus on mobile- and cloud solutions!
Today I released TinyMvvm 2.2 (2.2.2).
In this version I have added support for passing parameters when navigating with ShellNavigationHandler. You can now use both query parameters and passing a object as a parameter.
So in your ViewModel with ViewModelBase as the base class you can use it like this:
var persons = new List<string>()
{
"Daniel",
"Johan"
};
Navigation.NavigateToAsync($"{nameof(ContactViewModel)}?id=1", persons);
You can also use the NavigationHelper class to navigate.
NavigationHelper.Current.NavigateToAsync($"{nameof(ContactViewModel)}?id=1", persons);
In the receiving ViewModel, you can access the parameters via the QueryParameters- and NavigationParameter properties.
public class ContactViewModel : ViewModelBase
{
public async override Task Initialize()
{
await base.Initialize();
var id = (int)QueryParameters["id"];
var persons = (List<string>)NavigationParameter;
}
}
If you want to read more about TinyMvvm, I can recommend theese blog posts:
TinyMvvm 2.1.1 – Introducing ViewModel navigation
Introducing TinyMvvm 2.0
TinyMvvm – The best MVVM library for Xamarin.Forms!?
The full source code and documentation can be found on GitHub. Feedback and contribtions are very welcome.