Is it guaranteed that on IValueConverter ConvertBack call other views would update?

血红的双手。 提交于 2019-12-13 07:45:41

问题


Is it guaranteed that on IValueConverter ConvertBack call other views would update and how to enforce it?

I have 4 parameters in a List. Each pair of them can be calculated from another two in a manner like:

A = f(a,b)
B = f2(a,b)
a = f3(A,B)
b = f4(A,B)

I have them all rendered in one in a ItemsControl. I created a IValueConverter that can Convert and ConvertBack on demand. During Conversion Back of one item values for other three are updated in the source List. I wonder if it is guaranteed that after one List Item ConvertBack call others would be invoked?


回答1:


No, this is not guaranteed. IValueConverter does only convert the value which should be set on the model.

For the view to update based on that change, your model should implement INotifyPropertyChanged and raise the PropertyChanged event after a property was set.

Here is an example of a class that implements INotifyPropertyChanged:

public class TestClass : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    private string property;
    public string Property 
    { 
        get { return property; }
        set
        {
            property = value;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Property)));
        }
    }
}

Please note that you'd normally use a base class that implements that interface (provided by all MVVM libraries and frameworks).



来源:https://stackoverflow.com/questions/35805561/is-it-guaranteed-that-on-ivalueconverter-convertback-call-other-views-would-upda

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!