MvvmCross Android binding Enabled not work with Click

两盒软妹~` 提交于 2019-12-24 22:25:23

问题


I have a TextView bound with Enabled, Clickable and Click. When the activity is loaded, Enabled & Clickable were bound to false value but the TextView cannot be disabled & still be clickable. After changed the bound value to true & then false, the TextView is disabled.

I found that the issue was related to binding the Click event. Once Click is bound, the mentioned issue occurs. Without binding the Click event, it works as expected.

In the following sample code, the first 2 TextViews are ok. The last one with binding Click does not work.

BTW, I have this issue with TextInputEditText instead. I found the situation applies to TextView as well so I use TextView for illustration.

         <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;
        }
    }

Any idea how to fix?

Thanks


回答1:


As Stuart said, there are some interaction between ICommand.CanExecute and the Enabled property. Switching the binding to :

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

Effect.



来源:https://stackoverflow.com/questions/47668130/mvvmcross-android-binding-enabled-not-work-with-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!