似乎无法让 Timepicker 工作(C# / WPF)
我确信我在这里错过了一些很容易的东西。几乎所有针对 C#/WPF 的 Timepicker 的互联网搜索都会指向此网页: http://jobijoy.blogspot.com/2007/10/time-picker-user-control.html 因此我认为它可以正常工作。但是,当我将其复制/粘贴到用户控件并运行它时,该控件会按预期显示,但是当我单击数字并按向上或向下键时,没有任何反应。即使在调试模式下,在 KeyDown 事件的 switch case 上设置断点,也不会发生任何情况。它没有注册 KeyDown 事件。它应该关注包含 TextBlock 的网格,因此我尝试将 KeyDown 更改为 TextBlock,但无济于事。我似乎无法让它发挥作用! :( 我正在使用 Visual Studio 2008。
I'm sure I'm missing something very easy here. Pretty much any internet search for a Timepicker for C#/WPF points to this webpage: http://jobijoy.blogspot.com/2007/10/time-picker-user-control.html and as such I figured it would work correctly. However, when I copy/paste this into a user control and run it, the control shows up as it should, but when I click on the digits and press Up or Down, nothing happens. Even in debug mode with a break point on the switch case for the KeyDown event, nothing happens. It's not registering the KeyDown event. It's supposed to focus on the grid that contains the TextBlock, so I tried changing the KeyDown to the TextBlock, but to no avail. I cannot seem to get this to work! :( I'm using Visual Studio 2008.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
WPF 工具包中包含一个官方的 Microsoft DateTimePicker 控件。这将成为 .NET 4.0 框架的一部分
There is an official Microsoft DateTimePicker control included in the WPF Toolkit. This will be part of the framework in .NET 4.0
我认为由于某种原因,你的控制没有集中注意力。我也尝试过,但该活动也不会为我举办。 这篇文章可能会提供一些见解. 不过,在 Loaded 事件中手动将焦点设置到用户控件对我来说不起作用。
唯一对我有用的事情是执行以下所有操作:
当然,这只会让事件触发并正确注册,值似乎没有显示(甚至在我更改代码之前),但它处理了事件未触发的特定问题。
I think you're the control is not getting focused, for some reason. I tried it, too, and the event wouldn't fire for me, either. This post might offer some insight. Manually setting focus to the user control in the Loaded event didn't work for me, though.
The only thing that did work for me was doing all of the following:
Of course, this only got the event to fire and register properly, the values don't seem to show up (even before I changed the code), but it handles the specific issue of the event not firing.
silverlight 4 中有一个 DatePicker 和一个 TimePicker
如果您愿意,您可以使用它们创建自己的控件,或者简单地单独使用每个控件。
There's a DatePicker and a TimePicker in silverlight 4
If you want you can create your own control with those or simply use each one separated.