2010-04-24 3 views

답변

4

당신이 클래스의 속성으로 Timespan을 노출하는 가정하면,이 같은 INotifyPropertyChanged을 구현할 수 있습니다

public class MyClass : INotifyPropertyChanged 
{ 
    private Timespan _timespan; 

    public event PropertyChangedEventHandler PropertyChanged; 

    public Timespan Timespan 
    { 
     get { return _timespan; } 
     set 
     { 
      Timespan oldValue = _timespan; 
      _timespan = value; 

      if(oldValue != value) 
       OnPropertyChanged("Timespan"); 
     } 
    } 

    protected void OnPropertyChanged(string propertyName) 
    { 
     PropertyChangedEventHandler @event = PropertyChanged; 

     if(@event != null) 
      @event(
       this, 
       new PropertyChangedEventArgs(propertyName ?? string.Empty) 
       ); 
    } 
} 

재산 Timespan에 변경된 값의 모든 할당은 예상 이벤트를 발생합니다.