views:

280

answers:

1

I am using the DatePicker from WPFToolkit, but since the current date and the last/first day of the month is highlighted as well, it is confusing which date is actually selected.

How can I make it so nothing is highlighted in the calendar except the selected date?

alt text

+2  A: 

if I understood your question correctly you would like to do following: 1. hide the current date selection 2. make focus rectangle to be set on the selected date when calendar control pops up (or I guess get rid of it)

N1 is easy; you should set IsTodayHighlighted property of the DatePicker to false and it would disappear

N2 is a little trickier. There might be an easier way for fixing this but here's what working for me: DatePicker moves focus to the calendar control right after showing it by calling

calendar.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));

this makes focus rectangle to be shown on the first day of the month; you can fix it by forcing calendar to move focus to the selected date; below is an CalendarOpened event handler for the DatePicker control (datePicker1 in my case). I'm using reflection to access private field _calendar of the datapicker control and execute its private method FocusDate

private void datePicker1_CalendarOpened(object sender, RoutedEventArgs e)
{
    FieldInfo fieldInfo0 = datePicker1.GetType().GetField(
        "_calendar", BindingFlags.Instance | BindingFlags.NonPublic);            
    Microsoft.Windows.Controls.Calendar calendar = 
        (Microsoft.Windows.Controls.Calendar)fieldInfo0.GetValue(datePicker1);
    if (calendar != null)
    {
        MethodInfo focusDateInfo = calendar.GetType().GetMethod("FocusDate", BindingFlags.Instance | BindingFlags.NonPublic);
        focusDateInfo.Invoke(calendar, new object[] { datePicker1.SelectedDate });
    }
}

this would make calendar control look cleaner when it pops up; but would still show focus rectangle on the first day of the month if user would start selecting different months

hope this helps, regards

serge_gubenko