Forum Xamarin.Android

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Moving data between viewmodels MVVMCross

Hello!

I'm newbie in Xamarin and MVVMCross.

My app shows list of cars using MvxRecyclerView and I want to show full specification of selected car in new view. I did a navigation in my CarViewModel to CarItemViewModel but I have no idea how to pass object of selected car from my MVXRecyclerView to new view. I know how to solve this problem using "raw" C# and Android background but I should do it using MVVMCross mechanics (unfortunately, MVVMCross documentation is not helpful).

I would appreciate for any help.

Answers

  • smhasansmhasan KWMember ✭✭✭
    edited January 11

    @toledo1366
    There are 2 way to pass data in MVVM model
    1. Message Center ([https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/messaging-center])
    2. Second you can use AppPreferences Class like below

    ```
    public static class AppPreferences
    {
    #region SetLanguage
    public static void SetLanguage(string key, string value) { Preferences.Set(key, value); }
    public static string GetLanguage(string key) { return Preferences.Get(key, ""); }

        #endregion
    
        #region all data in json
        public static void SetJson(string key, string value) {Preferences.Set(key, value);}
    
        public static string GetJson(string key){return Preferences.Get(key, "");}
        #endregion
    

    }
    ```
    Use class where you want with Get and Set and proper key

Sign In or Register to comment.