Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Binding Failure performance hit vs Exception

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 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.

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.

like image 975
Aran Mulholland Avatar asked Apr 07 '10 00:04

Aran Mulholland


2 Answers

I haven't tested this myself but a blog post from the Visual Studio team says that binding errors indeed impact performance:

WPF tries several different ways to resolve path errors, including searching for attached properties and this is quite expensive.

like image 83
Livven Avatar answered Oct 15 '22 03:10

Livven


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.

like image 40
Kent Boogaart Avatar answered Oct 15 '22 02:10

Kent Boogaart