Xamarin.forms 如何在MVVMHelper的ViewModelBase类中直接使用BindableProberty

Xamarin.forms 如何在MVVMHelper的ViewModelBase类中直接使用BindableProberty,xamarin.forms,Xamarin.forms,我认为我的问题在于对OOP的误解,当我的类继承BindableObject时,我的代码工作正常,但当我的类继承MVVMhelper ViewModelBase时,SetValue和GetValue未在当前上下文中定义,但我需要在视图模型中使用bindable属性 public class TestViewModel : ViewModelBase { public TestViewModel() { } pu

我认为我的问题在于对OOP的误解,当我的类继承BindableObject时,我的代码工作正常,但当我的类继承MVVMhelper ViewModelBase时,SetValue和GetValue未在当前上下文中定义,但我需要在视图模型中使用bindable属性

  public class TestViewModel : ViewModelBase
   { 
         public TestViewModel()
          {
          }
         public static readonly BindableProperty IsWorkingProperty =
          BindableProperty.Create(nameof(IsWorking), typeof(bool), 
          typeof(TestViewModel), default(bool));

         public bool IsWorking
         {
           get { return (bool)GetValue(IsWorkingProperty); }
           set { SetValue(IsWorkingProperty, value); }
         }
    }
ViewModelBase是从inotifypropertychanged继承的mvvm帮助器基础视图模型,我说,当我用bindableobject重新使用ViewModelBase时,一切都在工作

您说过,ViewModelBase是一个类,实现了INotifyPropertyChanged接口,您在模型中将ViewModelBase替换为BindableObject类,一切正常。由于Bindableobject是抽象类,也实现了INotifyPropertyChanged接口,所以可以使用Bindableobject实现通知功能

我想在viewmodelbase中声明bindableproperty

我不知道为什么要在ViewModelBase中声明bindableproperty,若要这样做,必须继承BindableObject类。GetValue(BindableProperty)和SetValue用于访问由BindableProperty实现的属性的值,这些方法是adstract Bindableaobject方法


因为BindableObject类实现了INotifyPropertyChanged,所以您只需让ViewModelBase继承BindableObject。

,我不知道什么是ViewModelBase,是实现INotifyPropertyChanged接口的类?但若要在TestViewModel中创建BindableProperty,它应该继承BindableObject,请参阅“谢谢,ViewModelBase是mvvm helper base视图模型,它继承了inotifypropertychanged,我说,当我用bindableobject重新使用ViewModelBase时,一切都正常,但我想在viewmodelbaseOk中声明bindableproperty。谢谢,我完全更改了方法,没有实现新的bindableobjectproperty@immortal,如果我的回复有助于您解决问题,请记住将其标记为答案,谢谢。