Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVVMCross button command binding not firing

this is with regard to the following question on stackoverflow. I am trying to have a touch command for a button as described here but nothing happens. mvvmcross touch command binding in android

<Button
xmlns:local="http://schemas.android.com/apk/res/Test.UI.Droid"
android:text="Office"
android:layout_column="0"
android:id="@+id/imageButton1" 
local:MvxBind="{'Touch':{'Path':'ItemClickCommand'}}"/>  


public IMvxCommand ItemClickCommand
{
get
{
return new MvxRelayCommand(() => this.RequestNavigate<Tests.OfficeViewModel>(true));
}
}  

What am I doing wrong in the above code, why does it not fire.

like image 668
tribal Avatar asked Dec 07 '25 02:12

tribal


1 Answers

There's no binding in place for a Touch at present.

public event EventHandler<View.TouchEventArgs> Touch

If you wanted to add one, then search on StackOverflow for how to setup a new binding - e.g. the answer in mvvmcross touch command binding in android gives quite a full example.


However... for most button presses, you can probably just use:

public event EventHandler Click

Because it's an EventHandler rather than an EventHandler<TCustom> then this binds automagically.

i.e.:

<Button
xmlns:local="http://schemas.android.com/apk/res/Test.UI.Droid"
android:text="Office"
android:layout_column="0"
android:id="@+id/imageButton1" 
local:MvxBind="{'Click':{'Path':'ItemClickCommand'}}"/>  

should work - and it's probably what you are looking for - you want to respond to the Click of a button, not just a Touch?


To debug problems with binding it's worth looking at the MvxBindingTrace output - normally it will tell you when it can't bind to things - and if it doesn't, then please log bugs on github issues :)

like image 126
Stuart Avatar answered Dec 08 '25 16:12

Stuart



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!