MVVM Master to detail

ArmandCharbonnierArmandCharbonnier ✭✭FRMember ✭✭

Hello everyone,

I'm building most of my application with Xamarin.Forms and MVVM Light. I searched around the web for MVVM best practices, but i couldn't find a suitable answer.

Here's the context:

  • I have a master page and his viewmodel. The viewmodel call a web service and load all items in an observable collection.
  • When i click an item in the list (binded listview), i want to go to the detail page for this selected item.

Now here are my question :

  • 1) Should my observablecollection contains viewmodels and then i pass the selected one to the detail page ?
  • 2) Should I pass an ID to the detail page and then build initialize my detail viewmodel through a service using the id parameter ?
  • 3) Is there any performances drawbacks ? I mean:
    • In case 1, what if my listview display only 2 properties and my details pages 50 properties, why should i have a viewmodel with 50 properties in my listview, when i'm displaying only 2.
    • In case 2, assuming i have a specific listview viewmodel with only 2 field, then i pass the id, i probably make a 2nd call to the webservice to get the details information and initialize my detail viewmodel, where i could only make 1 and get everything on the first call.

I hope it's clear enough,

If i'm missing something or you have another way to achieve this, fill free to tell me :)

Best regards,

Armand

Best Answer

Answers

  • ShamnadShamnad ✭✭✭ USMember ✭✭✭

    @ArmandCharbonnier
    me too working with xamarin.forms mvvm and worked as like you mentioned. But later i had hear that there should bee a sqlite between observablecollection. Observable collection may cresh dealing with large data . i dont know more about but a little , also if you are dealing with an app like an E-commears you must need sqlite , using observable collection is a nice idea me too doing that and i think that is the right way :smile:

  • ArmandCharbonnierArmandCharbonnier ✭✭ FRMember ✭✭
    edited November 2015

    Thanks @Shamnad,

    but my question is more on the navigation and passing data parameter than ObservableCollection itself. I would use a SQLite database only if i've to persist data in my App. In this case i don't, because the data come from a web service only for display and i don't need to store them.

  • ShamnadShamnad ✭✭✭ USMember ✭✭✭
    edited November 2015

    @Shamnad said:
    @ArmandCharbonnier
    me too working with xamarin.forms mvvm and worked as like you mentioned. But later i had hear that there should bee a sqlite between observablecollection. Observable collection may cresh dealing with large data . i dont know more about but a little , also if you are dealing with an app like an E-commears you must need sqlite , using observable collection is a nice idea me too doing that and i think that is the right way :smile:

    ok ..you are right now i'm saving cart data in my app to sqlite db i think i have to rethink about that . In your case if you are asking data passing one page to another

    void list_ItemSelected (object sender, SelectedItemChangedEventArgs e) { this.IsEnabled = false; // passing values to next page MainItems if (e.SelectedItem == null) return; Navigation.PushAsync(new MainItems(e.SelectedItem as categoryDB)); ((ListView)sender).SelectedItem = null; this._list.IsEnabled = true; }
    here i'm passing a selected data to one page to another page from a view

    public MainItemViewModel(categoryDB _item) { }
    data receive here in a view model

    i don't know are you searching for this any how here i'm passing a data from a list to another page :smile:

  • ArmandCharbonnierArmandCharbonnier ✭✭ FRMember ✭✭

    Thank again for your answer @Shamnad,

    Well i'm not really searching on how to pass data between page, i'm more concerned about what's the right way, and performances drawback. That's why i explained the 2 ways i use to pass data, and i'm asking if it's a good way or what's the difference (with a lot of data, for memory etc...).

  • ArmandCharbonnierArmandCharbonnier ✭✭ FRMember ✭✭

    bump ?

Sign In or Register to comment.