似乎无法让 Timepicker 工作(C# / WPF)

发布于 2024-08-19 11:13:36 字数 477 浏览 1 评论 0原文

我确信我在这里错过了一些很容易的东西。几乎所有针对 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 技术交流群。

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

发布评论

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

评论(3

香橙ぽ 2024-08-26 11:13:36

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

凉世弥音 2024-08-26 11:13:36

我认为由于某种原因,你的控制没有集中注意力。我也尝试过,但该活动也不会为我举办。 这篇文章可能会提供一些见解. 不过,在 Loaded 事件中手动将焦点设置到用户控件对我来说不起作用。

唯一对我有用的事情是执行以下所有操作:

  • 将 TextBlock 更改为 TextBox 并将事件移动到那里(焦点对于 TextBox 来说非常明显)
  • 将事件中的强制转换更改为 FrameworkElement(这是 Name 属性的位置)来自)而不是 Grid
  • 将大小写更改为 TextBox 的名称(而不是网格的名称)
  • 将事件更改为 PreviewKeyDown (以注册光标键)

当然,这只会让事件触发并正确注册,值似乎没有显示(甚至在我更改代码之前),但它处理了事件未触发的特定问题。

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:

  • changing the TextBlock to a TextBox and moving the event there (focus is pretty evident with a TextBox)
  • changing the cast in the event to FrameworkElement (which is where the Name property comes from) instead of Grid
  • changing the case to the TextBox's name (instead of the grid's name)
  • changing the event to a PreviewKeyDown (to get the cursor keys to register)

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.

旧人哭 2024-08-26 11:13:36

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.

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