Click here to Skip to main content
15,921,210 members
Home / Discussions / C#
   

C#

 
GeneralRe: Setter for Property bubbling up a level? Pin
Henry Minute6-Jan-09 13:48
Henry Minute6-Jan-09 13:48 
GeneralRe: Setter for Property bubbling up a level? Pin
Henry Minute6-Jan-09 13:51
Henry Minute6-Jan-09 13:51 
GeneralRe: Setter for Property bubbling up a level? Pin
Eric Burns7-Jan-09 6:55
Eric Burns7-Jan-09 6:55 
GeneralRe: Setter for Property bubbling up a level? Pin
Henry Minute7-Jan-09 7:17
Henry Minute7-Jan-09 7:17 
AnswerOT: Is it really called 'class Object'? Pin
Jon Rista6-Jan-09 10:14
Jon Rista6-Jan-09 10:14 
GeneralRe: OT: Is it really called 'class Object'? Pin
Eric Burns6-Jan-09 11:11
Eric Burns6-Jan-09 11:11 
GeneralRe: OT: Is it really called 'class Object'? Pin
Jon Rista6-Jan-09 11:38
Jon Rista6-Jan-09 11:38 
AnswerRe: Setter for Property bubbling up a level? Pin
Pete O'Hanlon6-Jan-09 10:29
mvePete O'Hanlon6-Jan-09 10:29 
Well, one way to do this could be to implement INotifyPropertyChanged like so:
public class Vector : INotifyPropertyChanged
{
  private int _x;
  private int _y;
  private int _z;
  
  public int X
  {
    get
    {
      return _x;
    }
    set
    {
      if (_x != value)
      {
        _x = value;
        Changed("X");
      }
    }
  }

  public int Y
  {
    get
    {
      return _y;
    }
    set
    {
      if (_y != value)
      {
        _y = value;
        Changed("Y");
      }
    }
  }

  public int Z
  {
    get
    {
      return _z;
    }
    set
    {
      if (_z != value)
      {
        _z = value;
        Changed("Z");
      }
    }
  }

  private void Set()
  {
    // Do some set work here... and rely on the property changed event
    // firing so the containing object can respond to items that have changed
    // as a result of the notification.
  }

  #region INotifyPropertyChanged Members
  private PropertyChangedEventHandler _propertyChanged;
  /// <summary>
  /// The event handler for the PropertyChanged event.
  /// </summary>
  public event PropertyChangedEventHandler PropertyChanged
  {
    add
    {
      _propertyChanged += value;
    }
    remove
    {
      _propertyChanged -= value;
    }
  }
  /// <summary>
  /// Called whenever a property changes, this method is invoked.
  /// </summary>
  /// <param name="propertyName">The name of the property that changed.</param>
  protected virtual void Changed(string propertyName)
  {
    Set();

    PropertyChangedEventHandler handler = _propertyChanged;
    if (handler != null)
    {
      handler(this, new PropertyChangedEventArgs(propertyName));
    }
  }
  #endregion
}
As noted in the Set method, you can rely on the event being raised so that the container can respond to any changes you've introduced as a result of the Set method.

"WPF has many lovers. It's a veritable porn star!" - Josh Smith

My blog | My articles | MoXAML PowerToys



QuestionSource code from visio flow chart Pin
sree6-Jan-09 4:14
sree6-Jan-09 4:14 
AnswerRe: Source code from visio flow chart Pin
Dave Kreskowiak6-Jan-09 7:56
mveDave Kreskowiak6-Jan-09 7:56 
QuestionFiltering FileSystemWatcher Events By File Size Pin
rich_wenger6-Jan-09 4:03
rich_wenger6-Jan-09 4:03 
AnswerRe: Filtering FileSystemWatcher Events By File Size Pin
#realJSOP6-Jan-09 4:30
professional#realJSOP6-Jan-09 4:30 
GeneralRe: Filtering FileSystemWatcher Events By File Size Pin
rich_wenger6-Jan-09 8:08
rich_wenger6-Jan-09 8:08 
GeneralRe: Filtering FileSystemWatcher Events By File Size Pin
#realJSOP6-Jan-09 8:21
professional#realJSOP6-Jan-09 8:21 
GeneralRe: Filtering FileSystemWatcher Events By File Size Pin
rich_wenger6-Jan-09 8:40
rich_wenger6-Jan-09 8:40 
GeneralRe: Filtering FileSystemWatcher Events By File Size Pin
Dave Kreskowiak6-Jan-09 9:24
mveDave Kreskowiak6-Jan-09 9:24 
GeneralRe: Filtering FileSystemWatcher Events By File Size Pin
#realJSOP6-Jan-09 9:29
professional#realJSOP6-Jan-09 9:29 
GeneralRe: Filtering FileSystemWatcher Events By File Size Pin
rich_wenger6-Jan-09 11:19
rich_wenger6-Jan-09 11:19 
GeneralRe: Filtering FileSystemWatcher Events By File Size Pin
#realJSOP6-Jan-09 23:10
professional#realJSOP6-Jan-09 23:10 
AnswerRe: Filtering FileSystemWatcher Events By File Size Pin
Dave Kreskowiak6-Jan-09 7:53
mveDave Kreskowiak6-Jan-09 7:53 
GeneralRe: Filtering FileSystemWatcher Events By File Size Pin
rich_wenger6-Jan-09 8:10
rich_wenger6-Jan-09 8:10 
GeneralRe: Filtering FileSystemWatcher Events By File Size Pin
Dave Kreskowiak6-Jan-09 9:19
mveDave Kreskowiak6-Jan-09 9:19 
QuestionRegEx Pin
Abdul Rahman Hamidy6-Jan-09 3:51
Abdul Rahman Hamidy6-Jan-09 3:51 
AnswerRe: RegEx Pin
Simon P Stevens6-Jan-09 3:58
Simon P Stevens6-Jan-09 3:58 
AnswerRe: RegEx Pin
Wendelius6-Jan-09 3:58
mentorWendelius6-Jan-09 3:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.