views:

29

answers:

0

I created two viewmodel, MyViewModel, MyViewModel2. MyViewModel2 include MyViewModel as property. MyViewModel include one entity MyEntity from EF/WCF Ria Service.

In MyViewModel2, I want to capture any item changes in MyEntity for databinding. My code like below:

public class MyViewModel : ViewModelBase
{
        //....
        public MyViewModel(myEntity myEntity)
            : this()
        {
            //....
            this._myEntity = myEntity;
            this._myEntity.PropertyChanged += new PropertyChangedEventHandler(_myEntity_PropertyChanged);
            this.RaisePropertyChanged("MyEntity");
        }

        void _myEntity_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {                
            this.RaisePropertyChanged("MyEntity");            
        }

  private MyEntity _myEntity;
        public MyEntity MyEntity
        {
            get { return this._myEntity; }
            set
            {
                if (value != this._myEntity)
                {
                    this._myEntity = value;
                    RaisePropertyChanged("MyEntity");
                }
            }
        }
}


public class MyViewModel2 : ViewModelBase
{    
      public MyViewModel2(){
        this._MyViewModel =  new MyViewModel();
        this._MyViewModel.PropertyChanged += new PropertyChangedEventHandler(_MyViewModel_PropertyChanged);  
      }

       void _MyViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
           //do something here....
        }


        private MyViewModel _MyViewModel;
        public MyViewModel MyViewModel
        {
            get { return this._MyViewModel; }
            set
            {
                if (value != this._MyViewModel)
                {
                    this._MyViewModel = value;
                    RaisePropertyChanged("MyViewModel");
                }
            }
        }
}

then I run the app and change data in MyEntity, but I can't capture the changed event in MyViewModel2.

How to resolve this problem?