MvxListView Nested Binding Error

Is it possible to nest the associated MvxListView (mvvmcross android v3.1 series)?

I find that nested binding ends with:

MvxBind:Warning:  1.17 Unable to bind: source property source not found Property:Command on MenuSection

Our ViewModel is a bit like

   class SomeViewModel : MvxViewModel{
       public List<MenuSection> Sections{get;set;}
   }

Where

class MenuSection{
   public string Title{get;set;}
   public MenuItem[] Items{get;set;}
}
class MenuItem{
   public string Name {get;set;}
   public ICommand Command{get;set;}
}

A shortened version of axml with most non-mvx attributes removed looks like this:

layout / page _home.axml

<android.support.v4.widget.DrawerLayout>
  <FrameLayout android:id="@+id/content_frame"/>
  <Mvx.MvxListView
        local:MvxBind="ItemsSource Sections"
        local:MvxItemTemplate="@layout/item_menusection" />
</android.support.v4.widget.DrawerLayout>

layout / item _menusection.axml

<LinearLayout>
  <TextView local:MvxBind="Text Title"/>
  <Mvx.MvxListView
      local:MvxItemTemplate="@layout/item_menusection_item"
      local:MvxBind="ItemSource Items; ItemClick Command" />
</LinearLayout>

layout / item _menusection_item.axml

<TextView local:MvxBind="Text Name"/>
+3
source share
1 answer

This is because you are attaching an internal ListView to a MenuSection.

The Commmand property is in the MenuItem object, not in the MenuSection.

You need to move the command to MenuSection.

EDIT:

page_home.axml bound to SomeViewModel =>

ListView.Items SomeViewMode.Sections = >

, item_menusection.axml, MenuSection = >

( item_menusection.axml) ListView.Items MenuSections.Items = >

, item_menusection_item.axml, MenuItem = >

TextView.Text MenuItem.Name

item_menusection.axml: ListView.ItemClick MenuSections.Command ( )

, layout/item_menusection.axml

<LinearLayout>
  <TextView local:MvxBind="Text Title"/>
  <Mvx.MvxListView
      local:MvxItemTemplate="@layout/item_menusection_item"
      local:MvxBind="ItemSource Items; ItemClick Command" />
</LinearLayout>

ListView ItemSource ItemClick ().

, MenuItem, :

item_menusection_item click MenuItem.Command.

Command MenuSection MenuItem :

public class MenuSection
{
    public string Title{get;set;}
    public MenuItem[] Items{get;set;}    
    public ICommand Command { get { return new MvxCommand<MenuSection>((ms) => ms.Command.Execute(null)); } }
}
+1

All Articles