Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind Click function with parameter

In MVVM Cross for Android in Xamarin Studio,

I can write this in my .axml file to bind a click function to a button:

local:MvxBind="Click SendMessage"  

SendMessage is a public method on the MvxViewModel with the signature

public void SendMessage() 
{
//do stuff
}


However, I want to do something like like this,

local:MvxBind="Click SendMessage param1: foo, param2: bar"

which should call the method underneath with a signature like this,

public void SendMessage(T foo, T bar) 
{
//do stuff
}

where foo and bar might be the current selected item, or the object represented in a particular row of a table etc.

I can't see anywhere that points towards how to do this, and I am hoping that it is a native functionality! Can anyone help?

like image 948
Adam Diament Avatar asked Jul 14 '26 00:07

Adam Diament


2 Answers

The binding engine allows you to use either ICommand instances or public void methods. The latter only works if you also install the NuGet package MethodBinding.

As for the amount of parameters supported, it boils down to a single argument, which should correspond to the ViewModel bound to the item in the ListView.

like image 194
Cheesebaron Avatar answered Jul 15 '26 13:07

Cheesebaron


You can use an ICommand instead of a void to execute your code, here you can paas one parameter.

An other option is to bind the parameters you need to objects and access these objects in your code.

like image 22
BrunoVT Avatar answered Jul 15 '26 14:07

BrunoVT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!