TinyMvvm 2.2 – Shell Navigation Updates

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;
    }
}

Read more

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!?

Contribute

The full source code and documentation can be found on GitHub. Feedback and contribtions are very welcome.

  6/4/2020 - 7:09 AM