如何在WPF中使用DateTimePicker?
我不知道如何在 WPF 中使用 DateTimePicker 控件。 它在工具箱中不可用。
I have no idea how to use the DateTimePicker control in WPF. It is not available in the Toolbox.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
请注意:以下答案仅适用于 3.5 Framework 下的 WPF,因为 NET 4.0 运行时有自己的 日期时间控件。
默认情况下,WPF 3.5 没有像 winforms 那样提供日期时间选择器。
不过,WPF 工具包中添加了日期选择器由 Microsoft 制作,可以在此处下载。 我想它将成为未来版本框架的一部分。
添加对 WPFToolkit.dll 的引用非常简单,在工具箱中查看它并按照网站上的说明与您的应用程序一起分发。
在此之前,其他人已经创建了第 3 方选择器(您可能更喜欢),或者使用在 WPF 应用程序中使用 winforms 控件的不太理想的解决方案。
更新:这个问题非常相似这个,它还有一个指向 浏览日期选择器以及其他链接。
Please Note: The following answer only applied to WPF under the 3.5 Framework as NET 4.0 runtime has it's own datetime control.
By default WPF 3.5 does not come with a date time picker like winforms.
However a date picker has been added in the WPF tool kit produced by Microsoft which can be downloaded here. I guess it will become part of the framework in a future release.
It is simple to add a reference to the WPFToolkit.dll, see it in the tool box and distribute with your application by following the instructions on the website.
Before this was available other people had created 3rd party pickers (which you may prefer) or alternatively used the less ideal solution of using the winforms control in a WPF application.
Update: This so question is very similar this one which also has a link to a walk through for the datepicker along with other links.
这是刚刚出现的;)
.NET 4.0 运行时中有一个用于 WPF 的新 DatePicker 类:
http://msdn.microsoft.com/en- us/library/system.windows.controls.datepicker.aspx
另请参阅“WPF 中的新增功能”以了解更多不错的功能:
http://msdn.microsoft.com/en-us/library/bb613588。 ASPX
This just came in ;)
There is a new DatePicker class for WPF in the .NET 4.0 runtime:
http://msdn.microsoft.com/en-us/library/system.windows.controls.datepicker.aspx
Also see the "Whats new in WPF" for more nice features:
http://msdn.microsoft.com/en-us/library/bb613588.aspx
WPF 没有开箱即用的日期时间选择器。
但是,当然有很多第三方日期时间选择器:)
http://www.devcomponents.com/dotnetbar-wpf/WPFDateTimePicker.aspx
http://marlongrech.wordpress.com/2007/09/11/wpf-datepicker/
http://www.codeplex.com/AvalonControlsLib
只需快速谷歌一下即可找到更多信息!
There is no out of the box DateTime picker for WPF..
There are however a lot of third party DateTime pickers of course :)
http://www.devcomponents.com/dotnetbar-wpf/WPFDateTimePicker.aspx
http://marlongrech.wordpress.com/2007/09/11/wpf-datepicker/
http://www.codeplex.com/AvalonControlsLib
Just do a quick google to find more!
我认为之前没有提到过这个 DateTimePicker:
A WPF DateTimePicker That Works Like the One在 Winforms 中
那个是在 VB 中的,并且有一些错误。 我将其转换为 C# 并制作了修复了错误的新版本。
注意:我在 WPFToolkit 以便我可以使用 .NET 3.5 而不是 .NET 4。如果您使用的是 .NET 4,只需在 XAML 中删除对“wpftc”的引用即可。
I don't think this DateTimePicker has been mentioned before:
A WPF DateTimePicker That Works Like the One in Winforms
That one is in VB and has some bugs. I converted it to C# and made a new version with bug fixes.
Note: I used the Calendar control in WPFToolkit so that I could use .NET 3.5 instead of .NET 4. If you are using .NET 4, just remove references to "wpftc" in the XAML.
有关 WPF Extended WPF Toolkit Release 1.4.0 中嵌入的控件,请参阅
http://elegantcode.com/2011/ 04/08/extended-wpf-toolkit-release-1-4-0/
对于日历和日历 DatePicker演练请参考,
http://windowsclient.net/wpf/wpf35/wpf -35sp1-toolkit-calendar-datepicker-walkthrough.aspx
您可以通过 Microsoft Expression Studio 自定义外观
[使用编辑模板选项]
示例如下所示:
将以下命名空间添加到 xaml 页面
将以下内容添加到页面/窗口资源
在窗口中,您可以使用以下样式:
谢谢,
For the controls embedded in WPF Extended WPF Toolkit Release 1.4.0, please refer
http://elegantcode.com/2011/04/08/extended-wpf-toolkit-release-1-4-0/
For Calendar & DatePicker Walkthrough please refer,
http://windowsclient.net/wpf/wpf35/wpf-35sp1-toolkit-calendar-datepicker-walkthrough.aspx
And you can cutomize the look and feel by Microsoft Expression Studio
[Use Edit Template option]
Sample shows here:
Add following namespaces to xaml page
Add followings to Page/Window resources
And in Window you can use the style as
Thanks,
如果您想要一个没有外部库的产品,我确实改进了 Qwertie 的产品。 可以在这里找到: https://stackoverflow.com/a/69241500/9758687
If you want one without external libraries, I do have improved the one from Qwertie. It could be found here: https://stackoverflow.com/a/69241500/9758687
扩展工具包DateTimePicker >。
There is a
DateTimePicker
available in the Extended Toolkit.WPF Tool Kit中有DatePicker,但我在WPF ToolKit中没有看到DateTime Picker。 所以我不知道John所说的DateTimePicker控件是什么样的。
There is DatePicker in WPF Tool Kit, but I have not seen DateTime Picker in WPF ToolKit. So I don't know what kind of DateTimePicker control John is talking about.
请注意使用 DateTime 而不是 DateOnly。 为此我纠结了将近半天。
Be aware to use DateTime and not DateOnly. I struggled nearly a half day about this.