将 WPF Toolkit 日期选择器的值重置为“默认”价值

发布于 2024-09-06 04:56:53 字数 587 浏览 0 评论 0原文

当我第一次打开使用 wpf 工具包日期选择器的窗口时,它在日历中突出显示了今天的日期,但关联的文本框中没有任何内容(预计水印为 mm/dd/yyy)。

我想在用户选择日期并“提交”后将日期选择重置为初始状态,这样当他们再次使用它时,它就不会在他们之前选择的日期。例如,如果一个人选择了 2 个月后的日期,则重置时,文本框是 mm/dd/yyyy 水印,并且当日历打开时,它会以今天的日期作为“开始日期”。

我尝试了以下各种组合,但这不会重置文本:

//set date to today so it move the calendar to this date
mydatepicker.SelectedDate = DateTime.Now;
//reset since we don't want a date selected
mydatepicker.SelectedDate = null;
//reset the text
mydatepicker.Text = string.Empty;

如果我仅重置文本,则不会重置日历(选定的日期\开始)。但如果我设置日历,文本就会更新,而不仅仅是水印。

有什么想法吗?

谢谢

When I first open my window that uses the wpf toolkit datepicker it has today's date highlighted in the calendar but nothing in the associated textbox (expect a water mark of mm/dd/yyy).

I want to reset the datepick to that initial state after a user selects a date and "submits" so when they use it again it not at the date they previously selected. So for example if a person selected a date 2 months from now, when it is reset the text box is the mm/dd/yyyy watermark and when the calendar is opened it starts with today's date as the 'starting date'.

I've tried various combinations of the following but this doesn't reset the text:

//set date to today so it move the calendar to this date
mydatepicker.SelectedDate = DateTime.Now;
//reset since we don't want a date selected
mydatepicker.SelectedDate = null;
//reset the text
mydatepicker.Text = string.Empty;

If i reset just the text the calendar (selected date\starting) is not reset. But if i set the calendar the text is updated and not long just the watermark.

Any ideas?

Thanks

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

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

发布评论

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

评论(1

长亭外,古道边 2024-09-13 04:56:53

我相信您正在寻找的是 DisplayDate 属性。该属性不可为空,对应于日历控件中当前选择的日期。我在一个快速的一次性 WPF 应用程序中测试了以下内容,效果很好。注释掉设置 DisplayDate 的行给出了您所描述的行为。

datePicker1.SelectedDate = null;
datePicker1.DisplayDate = DateTime.Today;

I believe what you're looking for is the DisplayDate property. This property, which is not nullable, corresponds to the date currently selected in the calendar control. I tested the following in a quick one-off WPF app and it worked fine. Commenting out the line that set DisplayDate gave the behavior you describe.

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