0
votes

Considering the following code:

<Mvx.MvxListView
    android:id="@+id/items_list"
    style="@style/ListNoDividers"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:layout_above="@+id/footer_panel"
    android:layout_below="@+id/intro_text"
    local:MvxBind="ItemsSource Items;ItemClick DoItCommand"
    local:MvxItemTemplate="@layout/item_template" />

I know that when I tap in item in the list, the DoItCommand will be invoked and the binded item will be past as a command parameter.

How can I use the same in a non MvxListView, like on this code snippet:

<LinearLayout
    android:id="@+id/item1"
    style="@style/ItemStyle"
    local:MvxBind="Click DoItCommand, CommandParameter=PropertyInViewModel"
    android:layout_marginBottom="@dimen/HalfDefaultInnerMargin" />
<LinearLayout
    android:id="@+id/item1"
    style="@style/ItemStyle"
    local:MvxBind="Click DoItCommand, CommandParameter=OtherPropertyInViewModel"
    android:layout_marginBottom="@dimen/HalfDefaultInnerMargin" />

Bottom line is that I need to pass a property value to DoItCommand using the command parameter.

1
Does stackoverflow.com/a/22779090/373321 syntax work for you? - Stuart
It does the job! Thanks! :) - Pedro Lamas

1 Answers

1
votes

As pointed out in the comments, using a similar approach to this, solves the issue!

public class MyLinearLayout : LinearLayout
{
    public HhLinearLayout(Context context, IAttributeSet attrs)
        : base(context, attrs)
    {
        Click += LinearLayoutClick;
    }

    public ICommand Command { get; set; }

    public object CommandParameter { get; set; }

    private void LinearLayoutClick(object sender, EventArgs e)
    {
        var command = Command;
        var commandParameter = CommandParameter;

        if (command == null || !command.CanExecute(commandParameter))
        {
            return;
        }

        command.Execute(commandParameter);
    }
}