检测何时在 Silverlight 日历控件上单击某一天
我正在开发一些需要与 Silverlight DatePicker 类似功能的东西 - 将显示一个包含日历控件的弹出窗口,并且在用户单击日期或使用键盘选择日期并按 Enter/空格键后,弹出窗口应该关闭。
我可以很好地显示日历,但我无法弄清楚用户何时单击了一天或按下了 Enter/空格键。 SelectedDatesChanged
事件不会给出任何指示,表明用户是否单击了所选日期,或者只是用键盘跳过了该日期。
Reflector 显示 DatePicker 控件正在作弊,它使用 Calendar 控件上的内部 DayButtonMouseUp
事件。
有谁知道这个问题的解决方案?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过将 DayButtons 的 ClickMode 设置为“悬停”来实现此目的。
之后您可以访问 MouseLeftButtonDown 事件
You can achieve this by setting the ClickMode of the DayButtons to 'Hover'.
After this you can lsiten to the MouseLeftButtonDown-event
这不是一个非常干净的解决方案。此外,它没有正确考虑 BlackoutDates,因为按钮的 IsBlackOut 属性也是内部的。我可以在点击事件中手动检查这一点,但出于我的目的,我不需要支持这一点。
FindVisualChildByName 复制自 http://pwnedcode.wordpress.com/2009/04/01/find-a-control-in-a-wpfsilverlight-visual-tree-by-name/
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/