如何涂黑一周中的特定日期(日期选择器)[VB] [英] How to black out specific days of the week (datepicker) [VB]
问题描述
我想知道是否有可能使日历(DatePicker)中的特定日期变得不可用,更具体地说是每个星期一和星期二.我发现了类似的主题(如何创建仅包含星期日的DatePicker和>jQuery UI datepicker上的第一个星期)有关日期不正确的信息,但是,我无法针对自己的特定目的修改其代码.我正在VB.NET(WPF)中编写此应用程序.
I was wondering if it is possible to make particular days unavailable from the calendar (DatePicker), more specifically every Monday and Tuesday. I have found similar threads (How do create a DatePicker with only Sundays enabled? and Disable specific days of the week on jQuery UI datepicker) about blacking out dates, however, I have not been able to modify their code for my specific goal. I'm writing this application in VB.NET (WPF).
我到目前为止使用的用于涂黑日期的函数是:
The functions I used so far, for blacking out dates are:
Datepicker1.BlackoutDates.AddDatesInPast()
Datepicker2.BlackoutDates.Add(New CalendarDateRange(DateTime.Now.AddDays(1), DateTime.MaxValue))
第一个函数将删除过去的日期,第二个函数将删除所有将来的日期.因为第二个功能需要一个"DateRange",所以我无法根据需要更改此功能.
Where the first function will blackout the past-dates, and the second will black out all future dates. Because there is a 'DateRange' required for the second function, I'm not able to alter this function for my need.
预先感谢
杰里
推荐答案
我修改了其中一个示例,并提出了这个示例.
它对我有用.
I modified one of the examples and came up with this.
It worked for me.
private void MyDatePicker_CalendarOpened(object sender, RoutedEventArgs e)
{
MyDatePicker.DisplayDateStart = DateTime.Now;
MyDatePicker.DisplayDateEnd = DateTime.Now + TimeSpan.FromDays(1000);
var minDate = MyDatePicker.DisplayDateStart ?? DateTime.MinValue;
var maxDate = MyDatePicker.DisplayDateEnd ?? DateTime.MaxValue;
for (var d = minDate; d <= maxDate && DateTime.MaxValue > d; d = d.AddDays(1))
{
if (d.DayOfWeek == DayOfWeek.Monday || d.DayOfWeek == DayOfWeek.Tuesday)
{
MyDatePicker.BlackoutDates.Add(new CalendarDateRange(d));
}
}
}
这是一个奖励:防止某些日期被选中.
这篇关于如何涂黑一周中的特定日期(日期选择器)[VB]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!