Reputation: 119
Does WPF framework automatically get the updates from INotifyPropertyChanged
derived types to the Bindings
in the UI?
Or do I have to do it manually ?
Upvotes: 0
Views: 208
Reputation: 1622
semi-Manually :-)
When you implement "INotifyPropertyChanged" you will implement those methods (which are usually implemented the same)
#region INotifyPropertyChanged
protected void RaisePropertyChanged(string propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
if (PropertyChanged != null) { PropertyChanged(this, e); }
}
public event PropertyChangedEventHandler PropertyChanged;
#endregion
After that, when one of your properties has changed, you need to call "RaisePropertyChanged" with the name of the property that changed. usually in the setter of that property
Upvotes: 0
Reputation: 2665
Yes it is Semi manually,
string _tText;
public string Text
{
get { return _tText; }
set
{
_tText = value;
OnPropertyChanged("Text");
}
}
Here the property changed show call once the property is set with some value. OnPropertyChanged("Text");
Upvotes: 1
Reputation: 77364
If you implement INotifyPropertyChanged
correctly, it's automatically.
Upvotes: 2