Reputation: 10482
I am learning about WPF. I have now come to binding. Does the binding rely on reflection when using INotifyPropertyChanged
and is so, what is the price? I am considering using WPF for displaying data being streaming via UDP, but I fear that the overhead might be too great compared to WinForms.
Upvotes: 8
Views: 858
Reputation: 41393
Performance of binding depends on the type of object being bound. Reflection isn't used with respect to INotifyPropertyChanged, but is when resolving CLR properties.
Microsoft has a great write up on this: "Optimizing Performance: Data Binding".
Key details related to performance:
If the source object is a CLR object and the source property is a CLR property, the Windows Presentation Foundation (WPF) data binding engine has to first use reflection on the source object ... This sequence of reflection operations is potentially very time-consuming from a performance perspective.
The second method for resolving object references involves a CLR source object that implements the INotifyPropertyChanged interface, and a source property that is a CLR property. In this case, the data binding engine uses reflection directly on the source type and gets the required property. This is still not the optimal method, but it will cost less in working set requirements than the first method.
The third method for resolving object references involves a source object that is a DependencyObject and a source property that is a DependencyProperty. In this case, the data binding engine does not need to use reflection. Instead, the property engine and the data binding engine together resolve the property reference independently. This is the optimal method for resolving object references used for data binding.
...
WPF allows you to data bind to XML content; however, data binding to XML content is slower than data binding to CLR objects. Do not convert CLR object data to XML if the only purpose is for data binding.
(emphasis added)
Upvotes: 6
Reputation: 15237
Here's an MSDN article about it. This is a pretty common question I hear all the time.
But my thought is, unless you're running into a serious edge case scenario, you want to use binding in WPF. That's the way the whole system is designed.
Upvotes: 6