timu
timu

Reputation: 165

MvvmCross: Different ItemClick commands in MvxListView for multiple layout

I used the answer from this question (MvvmCross : dynamic item template selection for MvxListView) and successfully created a multi-layout MvxListView. But now what I couldn't figure out is how to give different ItemClick commands to different layouts. When I created the MvxListView in axml I gave the ItemClick command in local:MvxBind property but overriding that behavior in special cases is what I need. Does anyone have any suggestions?

Upvotes: 0

Views: 702

Answers (1)

timu
timu

Reputation: 165

Found the solution.

Creating a Custom MvxListView and overriding ExecuteCommandOnItem solved my problem. I also added a property called Parent to my custom MvxListView which I set in my activity. That way I got able to call parent functions.

Something like this :

public class EditMvxListView : MvxListView
{
    public EditStationsView Parent {
        get;
        set;
    }

    public EditMvxListView (Context context,IAttributeSet attrs) : base(context,attrs)
    {
    }


    protected override void ExecuteCommandOnItem (System.Windows.Input.ICommand command, int position)
    {
        var item = Adapter.GetRawItem (position) as Station;

        if (item.Name == "New Station") {
            Parent.ShowSearch ();
            return;
        }

        base.ExecuteCommandOnItem (command, position);
    }
}

Upvotes: 1

Related Questions