none
System.ComponentModel.PropertyChangedEventHandler not handling the event

    Question

  • Hi,

    I'm working in a wpf app that is binding controls to a class that implements INotifyPropertyChanged. I'm trying to track when there are changes to the underlying object by setting a flag whenever a property is changed. To do so, I wired up an event handler to the PropertyChanged event of the class like so:

    _facilityLogic.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(facilityLogic_PropertyChanged);
    
    ...
    
    public void facilityLogic_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
    {
      SetIsChanged();
    }
    
    Can anyone tell me why this event handler never gets called? The event is firing, but SetIsChanged() never gets called.

    Monday, October 18, 2010 11:34 PM

Answers

  • Can you post how you've implemented the PropertyChanged member of INotifyPropertyChanged as well as how you actually raise the event? One possibility is that one or more event handlers are being called before the event handler you've shown above. If an exception occurs in an earlier event handler, later event handlers will not get the opportunity to handle the event. Without seeing more of the code however, it's difficult to do more than speculate. You could try putting a try..catch around the code that raises the event and see if the catch block is entered.
    • Marked as answer by SamAgain Tuesday, October 26, 2010 9:51 AM
    • Unmarked as answer by _xr280xr_ Tuesday, October 26, 2010 3:21 PM
    • Marked as answer by _xr280xr_ Tuesday, October 26, 2010 5:21 PM
    Wednesday, October 20, 2010 9:01 PM

All replies

  • Can you post how you've implemented the PropertyChanged member of INotifyPropertyChanged as well as how you actually raise the event? One possibility is that one or more event handlers are being called before the event handler you've shown above. If an exception occurs in an earlier event handler, later event handlers will not get the opportunity to handle the event. Without seeing more of the code however, it's difficult to do more than speculate. You could try putting a try..catch around the code that raises the event and see if the catch block is entered.
    • Marked as answer by SamAgain Tuesday, October 26, 2010 9:51 AM
    • Unmarked as answer by _xr280xr_ Tuesday, October 26, 2010 3:21 PM
    • Marked as answer by _xr280xr_ Tuesday, October 26, 2010 5:21 PM
    Wednesday, October 20, 2010 9:01 PM
  • Make sure you raise the PropertyChanged event in your property setter.
    • Marked as answer by SamAgain Tuesday, October 26, 2010 9:51 AM
    • Unmarked as answer by _xr280xr_ Tuesday, October 26, 2010 3:21 PM
    Thursday, October 21, 2010 12:36 PM
  • Thanks for your replies. I didn't get an alert about them. PropertyChanged was raised in the setters. So I went back in to wrap it in a try catch and see if an exception was being thrown, and when I ran it, it all worked fine. I don't know what the problem was but it's working now so glad to see there's nothing special about that event. Thanks again.
    Tuesday, October 26, 2010 5:20 PM