如何使 WPFToolkit DatePicker 仅突出显示所选日期?

发布于 2024-08-14 05:05:57 字数 339 浏览 5 评论 0原文

我正在使用 WPFToolkit 中的 DatePicker,但由于当前日期和该月的最后/第一天也突出显示,实际选择的日期令人困惑。

如何才能使日历中除了所选日期之外不突出显示任何内容?

替代文本 http://www.deviantsart.com/upload/fhsmni.png

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 http://www.deviantsart.com/upload/fhsmni.png

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风蛊 2024-08-21 05:05:57

如果我正确理解你的问题,你会想要执行以下操作:
1.隐藏当前日期选择
2.当日历控件弹出时,使焦点矩形设置在选定的日期上(或者我想摆脱它)

N1很容易;你应该将 DatePicker 的 IsTodayHighlighted 属性设置为 false,它就会消失

N2 有点棘手。可能有一种更简单的方法来解决这个问题,但这对我有用:DatePicker 在显示日历控件后立即将焦点移动到日历控件,通过调用

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

此方法使焦点矩形在该月的第一天显示;您可以通过强制日历将焦点移至所选日期来修复此问题;下面是 DatePicker 控件的 CalendarOpened 事件处理程序(在我的例子中为 datePicker1)。我使用反射来访问 datapicker 控件的私有字段 _calendar 并执行其私有方法 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 });
    }
}

这将使日历控件在弹出时看起来更干净;但如果用户开始选择不同的月份,仍然会在该月的第一天显示焦点矩形

希望这有帮助,
问候

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文