具有属性的多个错误消息的IDataErrorInfo [英] IDataErrorInfo With Multiple Error Messages for a Property

查看:88
本文介绍了具有属性的多个错误消息的IDataErrorInfo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎其他人有此问题: Validation.HasError确实如果已经出现新错误,则不会再次触发

It appears someone else is having this issue: Validation.HasError does not trigger again if new error comes in while already true

Validation.Error不会使用最新的错误消息进行更新.

The Validation.Error is not updating with the latest error message.

它显示了先前的错误,而不是最后被实际调用的错误.当我记录每个退货时,PropertyX大于或PropertyX小于返回的值,但它不会在我的工具提示中显示该消息.它将显示必填".

It shows the previous error not the one that actually got called last. When I log each return, the PropertyX is greater than or PropertyX is less than is returned, but it does not display that message in my tooltip. It will displays "Required".

我还发现,当返回的PropertyX大于PropertyX或小于PropertyX时,不会调用我的工具提示转换器.

I also found that my converter for the tooltip does not get called when the PropertyX is greater than or PropertyX is less than is returned.

这是验证码:

    string this[string columnName] 
    {
        get
        {
            switch(columnName)
            {
                case "Property1":
                    int output;
                    if (true == string.IsNullOrEmpty(this.Property1))
                    {
                        return "Required";
                    } else if (true == int.TryParse(this.Property1, out output))
                    {
                        return "Invalid integer";
                    } else if (true == this.Property1Int.HasValue &&
                    true == this.Property2Int.HasValue)
                    {
                        if (this.Property1Int.Value < this.Property2Int.Value)
                        {
                            return "Property2 is greater than Property1";
                        }
                    }

                    break;
                case "Property2":
                    int output;
                    if (true == string.IsNullOrEmpty(this.Property2))
                    {
                        return "Required";
                    } else if (true == int.TryParse(this.Property2, out output))
                    {
                        return "Invalid integer";
                    } else if (true == this.Property1Int.HasValue &&
                    true == this.Property2Int.HasValue)
                    {
                        if (this.Property2Int.Value > this.Property1Int.Value)
                        {
                            return "Property2 is greater than Property1";
                        }
                    }

                    break;
            };

            return string.Empty;
        }
    }

这是怎么回事?

推荐答案

如果您像其他问题一样使用转换器,我很确定这不是做事情的最佳方法.特别是在动态环境(如WPF)中.

If you are using converter as in other question, them I'm prety sure its not the best way to do things. Especialy in dynamic enviorment like WPF.

因此,我建议直接绑定到(Validation.Errors).CurrentItem,而不是使用此处所述的转换器:

So I would recomend binding to (Validation.Errors).CurrentItem directly instead of using converter as described here:

http://joshsmithonwpf .wordpress.com/2008/10/08/binding-to-validationerrors0-without-creating-debug-spew/

这篇关于具有属性的多个错误消息的IDataErrorInfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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