Wednesday, December 1, 2010

XAML and cryptic error message

Got the following cryptic error message when running a WPF application (a XamlParseException):
A 'Binding' cannot be used within a '<usercontrol>' collection. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.
At first glance, everything looked good.  It might have been helpful if the error told me which property it was croaking on--but I guess MS can't learn to be specific with this XAML crap.  Fortunately, a quick google search and I stumbled onto a post where they identified thier problem when they got the same error: the owner in the DependencyProperty definition was not the control the property was on--changing it fixed their problem.  A second look at my code and I found I had done the same thing (the problem with cut-and-pasting).  Changing the owner type to the correct class fixed the problem.