2011-09-09 8 views
2
namespace MimicCreation 
{ 

    public class TreeManager : INotifyPropertyChanged 
    { 

     public TreeManager() { } 

     public TreeManager(string title, string type, string filename) 
     { 
      this.childElementsValue.CollectionChanged += this.OnCollectionChanged; 
      Title = title; 
      Type = type; 
      FileName = filename; 
     } 

     public string Title { get; set; } 

     public string Type { get; set; } 

     public string FileName { get; set; } 

     public override string ToString() 
     { 
      return Title; 
     } 

     private ObservableCollection<TreeManager> childElementsValue = new ObservableCollection<TreeManager>(); 

     public ObservableCollection<TreeManager> ChildElements 
     { 
      get { return childElementsValue; } 
      set { childElementsValue = value; } 
     } 

     public void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) 
     { 
      switch (e.Action) 
      { 
       case NotifyCollectionChangedAction.Add: 
        foreach (TreeManager item in e.NewItems) 
        { 
         ((System.ComponentModel.INotifyPropertyChanged)item).PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(OnPropertyChanged); 

        } 
        break; 
      } 
     } 

     public void OnPropertyChanged(object sender, PropertyChangedEventArgs e) 
     { 

     } 

    } 
} 

를 인터페이스 멤버를 구현하는 'System.ComponentModel.INotifyPropertyChanged.PropertyChanged'하지 않는다 : 오류 'MimicCreation.TreeManager'는 인터페이스 멤버를 구현하는 컴파일에 'System.ComponentModel.INotifyPropertyChanged.PropertyChanged'하지 않습니다. 관찰 가능한 컬렉션의 각 항목이 변경 될 때 알림에 액세스 할 수있게하려는 관찰 가능한 컬렉션이 있는데, 내가 잘못한 것을 볼 수 없습니다. 어떤 아이디어라도 제발?나는 다음과 같은 오류를 얻고있다

감사합니다.

답변

2

오류 메시지는 관찰 가능한 컬렉션과 아무 관련이 없습니다. TreeManagerINotifyPropertyChanged을 구현한다고 선언하면 인터페이스 멤버를 구현해야합니다.

documentation on INotifyPropertyChanged에 따르면이 작업을 수행하려면 컴파일러에서 불만을 나타내는 정확히 PropertyChanged 이벤트를 구현해야합니다.

4

당신은 6의 7의

첫째,이 클래스는 당신이 관찰 컬렉션 이벤트에 가입 할에서 INotifyPropertyChanged를 구현하지 않아도 모든 것.

또한 컬렉션에있는 항목이 변경되었는지 확인하기 위해 노력하고 있다면 (그리고이 질문을 읽는 방법입니다.) 직접 또는 fron ObservableObject를 상속하여 INotifyPropertyChanged를 구현해야합니다.

두 번째로 PropertyChanged를 구독해야 컬렉션을 변경할 수 없습니다.

관련 문제