WPF Data Binding and Custom DepenencyProperties.
The Problem: Just encountered the same issue with data bindings and decided to write a quick entry about it. In a wpf UserControl, I have a custom DependencyProperty, that property is bound to the data source in another wpf hosting control using xaml. Since I wanted the data source to be reset every time the UserControl loads, I set it to null in the control’s load event. After that, all of a sudden the control was no longer displaying any of the data I was binding to it. What happened was that wpf dropped the binding on the custom DependencyProperty, when I set it to null in the load event. I could have kept loading data until i was blue in the face, but none of it would have displayed in my control, because there was no binding to set the DependencyProperty.
The Solution: Instead of setting the property to null to clear it, instantiate it to an empty instance of the data source that it is supposed to hold.
Hope that saves someone some time.
Categories
Archives
Software Quotes
??Software Blogs
February 2012 M T W T F S S « Nov 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29





