1
votes

I am new to mvvmcross. I do not know how to bind touch event of a relative layout to a view model. Can someone help me on this. Thanks in advance.

1

1 Answers

2
votes

This is possible using standard MvvmCross code. For the viewmodel you can use something like:

public class SomeViewModel : MvxViewModel
{
    public IMvxCommand OpenSomethingCommand { get; private set; }

    public SomeViewModel ()
    {
        OpenSomethingCommand = new MvxCommand(() => ShowViewModel<SomeOtherNewViewModel>());
    }
}

Then for the layout in your android project, you can use:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clickable="true"
    local:MvxBind="Click OpenSomethingCommand"
    android:id="@+id/someLayout">
//Wrap any other layouts in here
</RelativeLayout>