Answer the question
In order to leave comments, you need to log in
What is the correct way to use INotifyPropertyChanged to notify the "parent" of an instance property change?
The problem is this: it is necessary to change the values in the collection when at least one of the fields in the object changes. If closer to the very idea of the code, then when changing the length of one of the pipe sections, you need to recalculate the others.
The architecture in the code is as follows: the parent abstract class public abstract class AbstractTube
from which the class is inherited public class TubingStage : AbstractTube
and a sheet of pipes is created
public class CollectionTubingStage : ObservableCollection<TubingStage>, INotifyPropertyChanged
{
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
public override double Lenght
{
get
{ return TLenght; }
set
{
TLenght = value;
NeedAutoAlign = true;
NotifyPropertyChanged("Lenght of stage has been changed!");
}
}
INotifyPropertyChanged
? It is not clear how to access the collection itself from a collection instance in order to modify it.
Answer the question
In order to leave comments, you need to log in
1. The ObservableCollection class already implements the INotifyPropertyChanged interface.
2. You are not calling the NotifyPropertyChanged method correctly. The parameter must be the name of the property that was changed. Those. it should be like this
3. It's more correct to write Leng th , not Leng ht
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question