限制 C# DatePicker
我需要为我的用户提供一种在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想你想看看
BlackoutDates
属性。您可以订阅DisplayDateChanged
当用户切换月份并重新初始化新月份的BlackoutDates
列表时捕获的事件。I think you want to look at the
BlackoutDates
property. You can subscribe to theDisplayDateChanged
Event to catch when the user switches months and reinitialize the list ofBlackoutDates
for that new month.根据您需要对用户清楚的程度,您可以使用控件的微妙颜色突出显示(前色、背景色)来指示错误。如果他们试图忽略警告,则使用消息框。
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.