【发布时间】:2019-06-28 03:29:05
【问题描述】:
我正在尝试使用 MvvmCross Visibility 插件使项目不可见。我正在使用 MvvmCross 5.7 和 MvvmCross Visibility 插件 5.7。
我尝试通过布局和瑞士绑定来绑定对象的可见性。
我有一个 ViewModel,它有一个适当的 ShouldShowBackButton:
public class TabViewModel : MvxViewModel
{
private bool _showBackButton;
public IMvxCommand NavigateCommand => new MvxCommand(this.Act, this.CanAct);
public bool ShouldShowBackButton
{
get => this._showBackButton;
set
{
this._showBackButton = value;
this.RaisePropertyChanged(() => this.ShouldShowBackButton);
}
}
private void Act()
{
this.ShowViewModel<ProfileFragmentViewModel>();
}
private bool CanAct()
{
return true;
}
}
这个 ViewModel 继承自实际的 ViewModel:
public class ProfileFragmentViewModel : TabViewModel
{
public ProfileFragmentViewModel()
{
this.ShouldShowBackButton = false;
}
}
viewModel 已正确绑定到 View,我已经对其进行了测试。 这是我试图使 TextView 不可见的方式:
<TextView
android:id="@+id/testProp"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:text="Test visibility"
local:MvxBind="Visibility Visibility(ShouldShowBackButton)" />
还有瑞士法典:
public class ProfileFragmentView : MvxFragment
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
var view = this.BindingInflate(Resource.Layout.ProfileFragmentView, null);
var backButton = view.FindViewById<Button>(Resource.Id.toolbarBackButton);
var testButton = view.FindViewById<TextView>(Resource.Id.testProp);
var set = this.CreateBindingSet<ProfileFragmentView, ProfileFragmentViewModel>();
set.Bind(testButton).For(v => v.Visibility).To(vm => vm.ShouldShowBackButton)
.WithConversion<MvxVisibilityValueConverter>();
set.Apply();
return view;
}
}
这两种方法都不会使我的 TextView 不可见。
【问题讨论】:
-
你能发布你的整个 ProfileFragmentView 布局文件吗?
标签: c# xamarin xamarin.android mvvmcross