karthick
karthick

Reputation: 371

xamarin mvvmcross binding relative layout

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.

Upvotes: 1

Views: 530

Answers (1)

Martijn00
Martijn00

Reputation: 3559

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>

Upvotes: 2

Related Questions