Is it possible to Bind Android TextView to Click event with MvvmCross? Or as alternative make a button which looks like TextView?
How to Bind Android TextView to Click event with MvvmCross
It is turned out that TextView can be bound same way as Button
local:MvxBind="Click DoCommand"
@AlexPetrenko: in your fragment var set = this.CreateBindingSet<YourFragment, YourViewModel> (); set.Bind (_textView).For (p => p.Click).To (vm => vm.YourCommand); set.Apply (); –
Aeronautics
it says click can only be used on left hand side –
Survival
You can bind a text view like this.
<TextView android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
local:MvxBind="Click DoThisCommand" />
height and width you can manage according to your convinience. Hope this will help you.
As the OP may be interested in methods to achieve click binding from code-behind as opposed to xml I have provided the following for guidance:
using MvvmCross.Platforms.Android.Binding;
var set = this.CreateBindingSet<theActivity,theViewModel>();
imageView1.For(x=> x.BindClick()).To(vm=>vm.imageViewClickCmd);
set.Apply()
The MvvmCross.Platforms.Android.Binding namespace provides the BindClick() extension method. Similar methods can be found for alternative events at the following links https://www.mvvmcross.com/documentation/fundamentals/data-binding#built-in-bindings
Alternatively you can use
imageView1.For("Click").To(vm=>vm.imageViewClickCmd);
© 2022 - 2024 — McMap. All rights reserved.