I
I
Ivan Kurnakov2014-05-19 08:59:56
Programming
Ivan Kurnakov, 2014-05-19 08:59:56

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 AbstractTubefrom which the class is inherited public class TubingStage : AbstractTubeand a sheet of pipes is created

public class CollectionTubingStage : ObservableCollection<TubingStage>, INotifyPropertyChanged
    {     
        
    }

There is an event handler and the event itself in the TubingStage class:
public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

And property code in the same class
public override double Lenght
        {
            get
            { return TLenght; }
            set
            { 
            TLenght = value;
            NeedAutoAlign = true;
            NotifyPropertyChanged("Lenght of stage has been changed!");
            }
        }

How can I use it correctly 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 answer(s)
R
Rifat, 2014-05-19
@Skinner2170

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 question

Ask a Question

731 491 924 answers to any question