PropertyChanged affects several properties

I have a situation where I have a couple of variables whose values ​​depend on each other as follows:

A is a function of B and C B is a function of A and C C is a function of A and B

Any value can be changed in the user interface. I make a notice of change and change as follows:

private string _valA;
private string _valB;
private string _valC;

public string ValA
{
    get { return _valA; }
    set
    {
        if (_valA != value)
        {
            _valA = value;
            RecalculateValues("ValA");       //Here ValB and ValC are calculated
            OnPropertyChanged("ValA");
        }
    }
}

public string ValB
{
    get { return _valB; }
    set
    {
        if (_valB != value)
        {
            _valB = value;
            RecalculateValues("ValB");       //Here ValA and ValC are calculated
            OnPropertyChanged("ValB");
        }
    }
}

(...)

private void RecalculateValues(string PropName)
{
    if (PropName == "ValA")
    {
       _valB = TotalValue * _valA;
       OnPropertyChanged("ValB");

       _valC = something * _valA
       OnPropertyChanged("ValC");
    }
    else
    (...)

}

, _valB, _valC (), PropertyChanged . - , , , . PropertyChanged , , ... , / .

? setter, . ( )?

, , - IdataErrorInfo / . , [columnName] , , , . IDataErrorInfo , (). ?

. ValidationRules , ViewModel.

+3
2

, , . 5 10 , .

WPF . , IEditableObject, BeginEdit, CancelEdit EndEdit, "EndEdit".

BeginEdit temp, CancelEdit temp Fire PropertyChaged , , EndEdit , , PropertyChanged .

IEditableObject , , , , .

, PropertyChanged, , , setter, .

+2

NotifyPropertyChanged , Calculate NotifyPropertyChanged . , . Setter: , , .

+1

Source: https://habr.com/ru/post/1726684/


All Articles