views:

81

answers:

1

I have a UserControl with a property of type Dictionary, called HighlightedDates. The property holds a set of dates, with a tool tip string for each date, and it works fine when set from code.

I want to bind the HighlightedDates property to a view model property, DatesWithNotes, of the same type, using this markup:

<MyControls:MyCalendar SelectedDate="{Binding SelectedDate}"
                       HighlightedDates="{Binding DatesWithNotes}" />

Unfortunately, I get this exception when I try to do that:

A 'Binding' cannot be set on the 'Value' property of type 'DictionaryEntry'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.

It looks like WPF is trying to bind an individual entry, not the Dictionary itself.

As an alternative, I am looking at having the view model push each new value added to its dictionary out to the user control's dictionary, which seems awfully clumsy. And that brings me to my question: Is there a way to make this binding work? Thanks for your help.

A: 

This problem gets more interesting. Karmicpuppet attempted to reproduce the error using a simple test project--see his comment above. He didn't get the error in his test, but I got it when I ran the same test.

I have read quite a bit about problems involved in databinding to a dictionary object. In my project, I refactored to eliminate the dictionary and moved on. I haven't heard any other suggestions, so I am going to close out this question.

David Veeneman
Your view model is exposing `MonthNotes`, but you are binging to `MonthDates`: `MyDictionary="{Binding Path=MonthDates...`
Jerod Houghtelling
Thanks--corrected. Still get the same error.
David Veeneman