MvvmCross能见度插件不会隐藏我的TextView

问题描述 投票:1回答:1

我试图让使用MvvmCross能见度插件无形的项目。我使用MvvmCross 5.7和MvvmCross能见度插件5.7。

我试图对象的可见无论是从外观,还与瑞士绑定绑定。

我有一个有分寸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;
        }
    }

该视图模型是继承的实际视图模型的:

 public class ProfileFragmentViewModel : TabViewModel
    {
        public ProfileFragmentViewModel()
        {
            this.ShouldShowBackButton = false;
        }
    }

视图模型被正确地绑定到视图,I`ve已经进行了测试。这是我试图让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不可见。

c# xamarin xamarin.android mvvmcross
1个回答
0
投票

你应该申报的财产作为反应

[Reactive]
public bool ShouldShowBackButton
    {
        get => this._showBackButton;
       ....
© www.soinside.com 2019 - 2024. All rights reserved.