【问题标题】:MvvmCross Android binding Enabled not work with ClickMvvmCross Android绑定已启用不适用于Click
【发布时间】:2017-12-06 19:09:28
【问题描述】:

我有一个TextView 绑定了 Enabled、Clickable 和 Click。加载 activity 时,已启用和 Clickable 绑定为 false 值,但 TextView 无法禁用且仍可单击。将绑定值更改为 true & 然后为 false 后,TextView 被禁用。

我发现问题与绑定 Click 事件有关。绑定 Click 后,就会出现上述问题。在不绑定 Click 事件的情况下,它可以按预期工作。

在下面的示例代码中,前 2 个TextViews 是可以的。最后一个有绑定Click的不行。

顺便说一句,我在TextInputEditText 上遇到了这个问题。我发现这种情况也适用于TextView,因此我使用TextView 进行说明。

         <TextView
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="test textview can be disabled at load"
             style="@style/EntryTextStyle"
             local:MvxBind="       Enabled RouteMarker.ArrivalNotice" />
         <TextView
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="test textview with no click command, can be disabled at load"
             style="@style/EntryTextStyle"
             local:MvxBind="       Enabled RouteMarker.ArrivalNotice;
                                   Clickable RouteMarker.ArrivalNotice" />
         <TextView
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="test textview with click command cannot be disabled at load"
             style="@style/EntryTextStyle"
             local:MvxBind="       Enabled RouteMarker.ArrivalNotice;
                                   Clickable RouteMarker.ArrivalNotice;
                                   Click DoSomethingCommand" />

    private IMvxAsyncCommand _doSomethingCommand;
    public IMvxAsyncCommand DoSomethingCommand
    {
        get
        {
            _doSomethingCommand = _doSomethingCommand ?? new MvxAsyncCommand(async () =>
            {
                await Task.Delay(10);
            });
            return _doSomethingCommand;
        }
    }

知道如何解决吗?

谢谢

【问题讨论】:

    标签: xamarin.android mvvmcross


    【解决方案1】:

    正如Stuart 所说,ICommand.CanExecuteEnabled 属性之间存在一些交互。将绑定切换到:

    local:MvxBind="Click DoSomethingCommand;Enabled RouteMarker.ArrivalNotice;Clickable RouteMarker.ArrivalNotice;"
    

    Effect.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-19
      • 1970-01-01
      • 1970-01-01
      • 2015-09-18
      • 1970-01-01
      相关资源
      最近更新 更多