【问题标题】:How to Bind Android TextView to Click event with MvvmCross如何使用 MvvmCross 将 Android TextView 绑定到 Click 事件
【发布时间】:2013-10-19 02:23:52
【问题描述】:

是否可以使用 MvvmCross 将 Android TextView 绑定到 Click 事件? 或者做一个看起来像 TextView 的按钮?

【问题讨论】:

    标签: android binding textview xamarin mvvmcross


    【解决方案1】:

    原来TextView可以和Button一样绑定

    local:MvxBind="Click DoCommand"
    

    【讨论】:

    • @AlexPetrenko: 在你的片段中 var set = this.CreateBindingSet (); set.Bind (_textView).For (p => p.Click).To (vm => vm.YourCommand); set.Apply();
    • 它说点击只能在左侧使用
    【解决方案2】:

    你可以像这样绑定一个文本视图。

               <TextView  android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    local:MvxBind="Click DoThisCommand" />
    

    您可以根据自己的方便管理高度和宽度。 希望这会对你有所帮助。

    【讨论】:

      【解决方案3】:

      由于 OP 可能对从代码隐藏而不是 xml 实现点击绑定的方法感兴趣,因此我提供了以下指导:

      using MvvmCross.Platforms.Android.Binding;
      
      var set = this.CreateBindingSet<theActivity,theViewModel>();
      imageView1.For(x=> x.BindClick()).To(vm=>vm.imageViewClickCmd);
      set.Apply()
      

      MvvmCross.Platforms.Android.Binding 命名空间提供了 BindClick() 扩展方法。类似的方法可以在以下链接中找到替代事件https://www.mvvmcross.com/documentation/fundamentals/data-binding#built-in-bindings

      你也可以使用

          imageView1.For("Click").To(vm=>vm.imageViewClickCmd);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-10-18
        • 1970-01-01
        • 1970-01-01
        • 2020-06-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多