Reputation: 4840
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?
Upvotes: 3
Views: 172
Reputation: 723
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.
Upvotes: 1
Reputation: 24460
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.
Upvotes: 1
Reputation: 2183
Being a bit illiteracy with the exact functionality in xamarin studio, I would like to suggest a general different approach:
How about letting the controls on your View set a class wide property SelectedItem
when they're selected, that could then be accessed by the buttons method when it's clicked?
Upvotes: 0