Bind Click function with parameter

As MVVM Cross

for Android in Xamarin Studio,

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

local:MvxBind="Click SendMessage"  

      

SendMessage

is a public method in MvxViewModel with signature

public void SendMessage() 
{
//do stuff
}

      


However, I want to do something like this,

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

      

which should call the method below it with a signature like this,

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

      

where foo and bar can be the currently selected item, or an object represented in a specific row in a table, etc.

I don't see anywhere that indicates how to do this and I hope this is native functionality! Can anyone please help?

+3


source to share


3 answers


The binding mechanism allows you to use either tags ICommand

or public void

. The latter only works if you also install the MethodBinding NuGet package .



As far as the number of options supported, it boils down to a single argument that must match the binding ViewModel

to the item in the ListView.

+1


source


To execute the code you can use ICommand instead of void, here you can specify one parameter.



Another option is to bind the parameters you need to the objects and access those objects in your code.

+1


source


Being a bit illiterate with the exact functionality in xamarin studio, I would like to suggest a general approach:

How about making the controls in your view set a property of the class SelectedItem

when they are selected so they can be accessed by the buttons method on click?

0


source







All Articles