If you make your Category class implement INotifyPropertyChanged, you can handle events when a property changes.
To do so, you have to change your property from a simple property:
// will NOT raise event
public string Name { get; set; }
to something more like:
// will raise event
public string Name
{
get { return _Name; }
set
{
if (_Name != value)
{
_Name = value;
OnPropertyChanged("Name");
}
}
}
private string _Name;
and then implement INotifyPropertyChanged in your class as well:
public event EventHandler<PropertyChangedEventArgs> PropertyChanged;
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (PropertyChanged != null)
PropertyChanged(this, e);
}
protected virtual void OnPropertyChanged(string propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
Now, when adding a Category object to your ComboBox, subscribe to the PropertyChanged event which will be raised every time the Name property changes.
An Even Better Way
Consider using the Binding class to populate your ComboBox. Binding automagically uses INotifyPropertyChanged to update the display when a property value changes.