限制 C# DatePicker

发布于 2024-12-09 05:32:29 字数 338 浏览 1 评论 0原文

我需要为我的用户提供一种在 WPF 应用程序中选择任何有效星期六的方法。现在,我只使用 DatePicker,如果一周中的某一天不是星期六,则会出错。

DateTime selectedDate = Convert.ToDateTime(datePicker1.ToString());
if (selectedDate.DayOfWeek != DayOfWeek.Saturday)
{
    MessageBox.Show("Please pick a Saturday");
}

我宁愿在控件中执行此操作,然后简单地滑回到下周六或使周日至周五不可点击。这应该很容易,但我画了一个空白。

I need to give my users a way of selecting any valid Saturday in a WPF app. Right now, I just use the DatePicker and error if the day of the week isn't Saturday.

DateTime selectedDate = Convert.ToDateTime(datePicker1.ToString());
if (selectedDate.DayOfWeek != DayOfWeek.Saturday)
{
    MessageBox.Show("Please pick a Saturday");
}

I'd rather do it in the control and simply slide back to the next Saturday or make Sun-Fri unclickable. This should be easy, but I'm drawing a blank.

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

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

发布评论

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

评论(2

Oo萌小芽oO 2024-12-16 05:32:29

我想你想看看 BlackoutDates 属性。您可以订阅 DisplayDateChanged 当用户切换月份并重新初始化新月份的 BlackoutDates 列表时捕获的事件。

I think you want to look at the BlackoutDates property. You can subscribe to the DisplayDateChanged Event to catch when the user switches months and reinitialize the list of BlackoutDates for that new month.

半城柳色半声笛 2024-12-16 05:32:29

根据您需要对用户清楚的程度,您可以使用控件的微妙颜色突出显示(前色、背景色)来指示错误。如果他们试图忽略警告,则使用消息框。

Depending on how clear you need to be to the user, you could use subtle color highlighting of the control (forecolor, backcolor) to indicate an error. Then use the message box for if they try to ignore the warning.

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