我正在尝试用MvvmCross将简单命令绑定到Android的按钮。
问题是,在我绑定命令之后,按钮将变为禁用状态。
已删除绑定
local:MvxBind="Click GotoScreen2Command"
为什么会发生这种情况,我如何解决它?
MainContainerViewModel.cs
:
public class MainContainerViewModel : BaseViewModel
{
readonly IMvxNavigationService _navigationService;
public IMvxAsyncCommand GotoScreen2Command { get; set; }
public MainContainerViewModel(IMvxNavigationService navigationService)
{
_navigationService = navigationService;
GotoScreen2Command = new MvxAsyncCommand(NavigateToScreen2Async);
}
private Task NavigateToScreen2Async()
{
return _navigationService.Navigate<Screen2ViewModel>();
}
}
fragment_main.axml
:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btn_goToScreen2"
android:text="Go to Screen2"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
local:MvxBind="Click GotoScreen2Command"/>
</android.support.constraint.ConstraintLayout>
以下是我的Android观点。
MainFragment.cs
[MvxFragmentPresentation(typeof(MainContainerViewModel), Resource.Id.content_frame)]
public class MainFragment : BaseFragment<MainViewModel>
{
protected override int FragmentLayoutId => Resource.Layout.fragment_main;
}
以及
MainContainerActivity.cs
:
[Activity(
Theme = "@style/AppTheme",
WindowSoftInputMode = SoftInput.AdjustResize | SoftInput.StateHidden)]
public class MainContainerActivity : BaseActivity<MainContainerViewModel>, IDrawerActivity
{
protected override int ActivityLayoutId => Resource.Layout.activity_main_container;
}