Silverlight’s DatePicker and Telerik’s RadWindow Dialog

In my current Silverlight project, I’m using the DatePicker control, which is part of the Silverlight SDK.

In one scenario, the DatePicker with TwoWay binding is embedded into a User Control, which itself is embedded into another User Control. The format is “dd.MM.yyyy”. Entering e.g. 23.11.2011 works fine, means the value of the bound property is set to the 23rd of November in 2011.

Then I needed a date input inside of a modal dialog. Shouldn’t be a problem, so I just copied and pasted the XAML from the User Control into the dialog’s XAML. But entering 23.11.2011 in the dialog, the bound property remains null. First I thought there was a binding issue at all, but after some playing around I noticed that entering 8.11.2011 worked fine. The bound property was set correctly to the 8th of November 2011. But as soon as the entered day was bigger than 12 – the maximum value of a month – the input was ignored.

Luckily, I already had a DateConverter created in that project. This converter parses the entered string in the ConvertBack method using the current culture. So I bound the DatePicker control to that converter too, set a breakpoint at the ConvertBack method, and stepped into it. And to my surprise, the entered values was interpreted and bound correctly now.

To me, the behavior does not make sense. Why does the Date Picker control act different in these two scenarios? One thing might be that the RadWindow as the parent somehow changes the culture. But from my understanding, this should lead to the 11th of August 2011 when entering 8.11.2011.

At least I’m happy that I found a workaround. I do not have to understand everything at all…