How to raise PropertyChanged event for child properties?

828 views Asked by At

What i want to do is bind controls to an object, i have as a taxonomy. The problem im running into is when i do something like

private Taxonomy _currentTaxonomy = new Taxonomy() { TaxonomyID=0 };

public Taxonomy CurrentTaxonomy{
    get;
    set{
          _currentTaxonomy = value
          NotifyPropertyChanged("Taxonomy");
    }
}

This way when the taxonomy gets set it does a notification. But the problem is that I have controls that are bound to the values inside that taxonomy, that do not get notified when the taxonomy is set. So if I load a new taxonomy, no notifications are made.

For example using the Entity Framework if i try setting taxonomy like so:

CurrentTaxonomy = context.Taxonomies.Find(2);

The notify event, which looks like so:

public int TaxonomyID { 
    get { return _TaxonomyID; } 
    set { _TaxonomyID = value; NotifyPropertyChanged("TaxonomyID"); } 
}

Does not get fired.

By request, the textbox binds like so:

tbTitle.DataBindings.Add("Text", _currentTaxonomy, "Title", false, DataSourceUpdateMode.OnPropertyChanged);
1

There are 1 answers

0
Piyush Parashar On BEST ANSWER

You should databind to the property name TaxonomyID. Assuming your BindingSource.DataSource is pointing to CurrentTaxonomy class.

tbTitle.DataBindings.Add("Text", _currentTaxonomy, "TaxonomyID", false, DataSourceUpdateMode.OnPropertyChanged);

See this post:

C# DataBinding - automatically writing changed property to label or textbox