数据绑定通知 INotifyPropertyChanged

 

class BackgroundPath: INotifyPropertyChanged
    {
        BitmapImage bindSource = new BitmapImage(new Uri(PathShow.ImageSelected));      //预设值

        public event PropertyChangedEventHandler PropertyChanged;

        public BitmapImage BindSource
        {
            set
            {
                SetProperty(ref bindSource, value, "BindSource");}           
            get
            {
                return bindSource;}           
        }

        protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName]string propertyName = null)
        {
            if (object.Equals(storage, value))
                return false;

            storage = value;
            OnPropertyChanged(propertyName);
            return true;
        }

        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
   }


      Binding bind = new Binding()
      {
        Source = new BackgroundPath(),
        Path = new PropertyPath("BindSource")
      };
      faceImge.SetBinding(Image.SourceProperty,bind);

 

 

posted @ 2017-06-13 18:06  韵切  阅读(224)  评论(0编辑  收藏  举报