I am developing something that will require similar functionality to the Silverlight DatePicker - a popup containing a Calendar control will be shown, and after the user clicks a date, or uses the keyboard to select a date and presses enter/space, the popup should close.
I can show the calender just fine, but I am at a loss at figuring out when the user has clicked a day or pressed enter/space. The SelectedDatesChanged
event does not give any indication of whether the user clicked the selected date, or was just passing over it with the keyboard.
Reflector shows that the DatePicker control is cheating, using an internal DayButtonMouseUp
event on the Calendar control.
Does anyone know a solution to this problem?
You can achieve this by setting the ClickMode of the DayButtons to 'Hover'. After this you can lsiten to the MouseLeftButtonDown-event
Not a very clean solution. Also, it does not properly take into account BlackoutDates because the IsBlackOut property of the button is also internal. I could manually check against that in my click event, but for my purposes I didn't need to support that.
FindVisualChildByName is copied from http://pwnedcode.wordpress.com/2009/04/01/find-a-control-in-a-wpfsilverlight-visual-tree-by-name/