难道保证上的IValueConverter ConvertBack调用其他的视图将更新? [英] Is it guaranteed that on IValueConverter ConvertBack call other views would update?

查看:420
本文介绍了难道保证上的IValueConverter ConvertBack调用其他的视图将更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它是保证上的IValueConverter ConvertBack调用其他视图将更新,以及如何执行呢?

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

我在列表中有4个参数。每对他们可以从另外两个的方式来计算,如:

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)

我把它们都呈现在一个一个的ItemsControl。我创建了一个的IValueConverter可以按需转换和ConvertBack。在转换为回其他三个一项价值在源列表被更新。
 我不知道是否可以保证一个列表项后调用ConvertBack别人会被调用?

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?

推荐答案

没有,这是不能保证。 的IValueConverter 并只转换应该对模型设置的值。

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

有关视图更新基于这种变化,你的模型应该实施<一个href=\"https://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged%28v=vs.110%29.aspx\"相对=nofollow> INotifyPropertyChanged的 ,提高<一个href=\"https://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.propertychanged%28v=vs.110%29.aspx\"相对=nofollow> 的PropertyChanged 事件属性设置后。

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

下面是一个类的实例,它实现 INotifyPropertyChanged的

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)));
        }
    }
}

请注意,您通常使用实现该接口(由所有MVVM库和框架提供)的基类。

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

这篇关于难道保证上的IValueConverter ConvertBack调用其他的视图将更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆