WPF 绑定失败性能与异常 [英] WPF Binding Failure performance hit vs Exception

查看:31
本文介绍了WPF 绑定失败性能与异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们绑定到异构对象集合时,并非所有对象都具有相同的属性集.在输出窗口中,我们收到如下消息:

when we bind to heterogeneous collection of objects, not all objects have the same set of properties. in the output window we get a message like:

System.Windows.Data 错误:39:BindingExpression 路径错误:找不到RoundingFactor"属性'object' ''MultiLineTextMarkingScheme'(HashCode=7262386)'.BindingExpression:Path=RoundingFactor;........

System.Windows.Data Error: 39 : BindingExpression path error: 'RoundingFactor' property not found on 'object' ''MultiLineTextMarkingScheme' (HashCode=7262386)'. BindingExpression:Path=RoundingFactor;..........

这似乎不是一个例外,但我们担心它会影响性能.

This doesn't appear to be an exception, but we are concerned it has a performance impact.

我们是否应该担心并创建一个视图模型,该模型具有我们希望绑定的所有属性(并且让底层元素上不存在的属性返回 null),或者我们可以直接保留它.

Should we be concerned and create a view model that has all the properties we wish to bind to (and have the properties that dont exist on the underlying element return null) or can we just leave it.

这种情况经常发生在可能存在大量此类绑定失败的网格场景中.

This situation often occurs in a grid scenario where there might be large numbers of these binding failures.

推荐答案

您只能看到该输出,因为您在 Visual Studio 中运行.通常这些跟踪语句无处可去,因为没有跟踪侦听器.无论哪种方式,对性能的影响都可以忽略不计.

You're only seeing that output because you're running inside Visual Studio. Normally those trace statements go nowhere because there is no trace listener. Either way, the performance implications are completely negligible.

另一方面,异常将是报告绑定失败的一种非常昂贵的方式,特别是因为 - 正如您所注意到的 - 通常有一些绑定对某些对象有效,但对其他对象无效.

Exceptions, on the other hand, would be a very costly way of reporting binding failures, particularly because - as you note - there are often bindings that work against some objects but not others.

这篇关于WPF 绑定失败性能与异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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