Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在windows应用程序中阻止日期_C#_Windows_Xaml_Datepicker - Fatal编程技术网

C# 在windows应用程序中阻止日期

C# 在windows应用程序中阻止日期,c#,windows,xaml,datepicker,C#,Windows,Xaml,Datepicker,我正在Windows应用程序(平板电脑桌面)中使用DatePicker。我想阻止日期选择器上的某些日期,以便用户无法选择它们。我查阅了谷歌的msdn,但找不到太多的信息 我得到了使用“DisplayDateStart”、“DisplaydateEnd”的建议,但当我使用它们时,我得到了错误——“DatePicker不包含DisplayDateStart的定义,并且找不到接受DatePicker类型的第一个参数的扩展方法DisplayDateStart” 请分享您对如何使其工作的想法 XAML:

我正在Windows应用程序(平板电脑桌面)中使用DatePicker。我想阻止日期选择器上的某些日期,以便用户无法选择它们。我查阅了谷歌的msdn,但找不到太多的信息

我得到了使用“DisplayDateStart”、“DisplaydateEnd”的建议,但当我使用它们时,我得到了错误——“DatePicker不包含DisplayDateStart的定义,并且找不到接受DatePicker类型的第一个参数的扩展方法DisplayDateStart”

请分享您对如何使其工作的想法

XAML:


XAML.cs

        DatePicker datePickerWithBlackoutDates = new DatePicker();            

        datePickerWithBlackoutDates.DisplayDateStart = new DateTime(2009, 8, 1);
        datePickerWithBlackoutDates.DisplayDateEnd = new DateTime(2009, 8, 31);
        datePickerWithBlackoutDates.SelectedDate = new DateTime(2009, 8, 10);

        datePickerWithBlackoutDates.BlackoutDates.Add(
            new CalendarDateRange(new DateTime(2009, 8, 1), new DateTime(2009, 8, 2)));
        datePickerWithBlackoutDates.BlackoutDates.Add(
            new CalendarDateRange(new DateTime(2009, 8, 8), new DateTime(2009, 8, 9)));
        datePickerWithBlackoutDates.BlackoutDates.Add(
            new CalendarDateRange(new DateTime(2009, 8, 15), new DateTime(2009, 8, 16)));
        datePickerWithBlackoutDates.BlackoutDates.Add(
            new CalendarDateRange(new DateTime(2009, 8, 22), new DateTime(2009, 8, 23)));
        datePickerWithBlackoutDates.BlackoutDates.Add(
            new CalendarDateRange(new DateTime(2009, 8, 29), new DateTime(2009, 8, 30)));

        datePickerWithBlackoutDates.DateValidationError +=
            new EventHandler<DatePickerDateValidationErrorEventArgs>(DatePicker_DateValidationError);

        // root is a Panel that is defined elsewhere.
        spDatePicker.Children.Add(datePickerWithBlackoutDates);
DatePicker datePickerWithBlackoutDates=new DatePicker();
datePickerWithBlackoutDates.DisplayDateStart=新日期时间(2009,8,1);
datePickerWithBlackoutDates.DisplayDateEnd=新的日期时间(2009,8,31);
datePickerWithBlackoutDates.SelectedDate=新日期时间(2009,8,10);
datePickerWithBlackoutDates.BlackoutDates.Add(
新日历日期范围(新日期时间(2009,8,1),新日期时间(2009,8,2));
datePickerWithBlackoutDates.BlackoutDates.Add(
新日历日期范围(新日期时间(2009,8,8),新日期时间(2009,8,9));
datePickerWithBlackoutDates.BlackoutDates.Add(
新日历日期范围(新日期时间(2009,8,15),新日期时间(2009,8,16));
datePickerWithBlackoutDates.BlackoutDates.Add(
新日历日期范围(新日期时间(2009,8,22),新日期时间(2009,8,23));
datePickerWithBlackoutDates.BlackoutDates.Add(
新日历日期范围(新日期时间(2009,8,29),新日期时间(2009,8,30));
datePickerWithBlackoutDates.DateValidationError+=
新事件处理程序(DatePicker\u DateValidationError);
//root是在别处定义的面板。
spDatePicker.Children.Add(datePickerWithBlackoutDates);
非常感谢你的帮助。 谢谢
Rao

使用日历日期选择器,您看到的是wpf控件,它与windows应用商店api没有完全相同的功能。

依照


嗨,我试过了,但它说找不到“CalendarDatePicker”。我刚刚生成了一个新的商店项目,添加了一个按钮,并在其中添加了第一行,效果很好。MinYear不存在,你需要MinDate代替(从我上面发布的url看)。确保在文件顶部有以下导入:使用Windows.UI.Xaml.Controls;啊。。抱歉,我刚刚意识到我读这篇文章是作为Windows应用商店,你是在做桌面澄清,对吗?不是商店?从桌面WPF应用程序的角度来看,您的代码在我的系统上用新的WPF应用程序编译得很好。Speciallyl-你正在创建哪种应用程序类型?嗨,亚当,我创建了一个通用应用程序(Windows 8.1)。我不确定这是否是WPF。我对windows开发相当陌生抱歉,我想我提到了应用商店,但它是windows应用。
        DatePicker datePickerWithBlackoutDates = new DatePicker();            

        datePickerWithBlackoutDates.DisplayDateStart = new DateTime(2009, 8, 1);
        datePickerWithBlackoutDates.DisplayDateEnd = new DateTime(2009, 8, 31);
        datePickerWithBlackoutDates.SelectedDate = new DateTime(2009, 8, 10);

        datePickerWithBlackoutDates.BlackoutDates.Add(
            new CalendarDateRange(new DateTime(2009, 8, 1), new DateTime(2009, 8, 2)));
        datePickerWithBlackoutDates.BlackoutDates.Add(
            new CalendarDateRange(new DateTime(2009, 8, 8), new DateTime(2009, 8, 9)));
        datePickerWithBlackoutDates.BlackoutDates.Add(
            new CalendarDateRange(new DateTime(2009, 8, 15), new DateTime(2009, 8, 16)));
        datePickerWithBlackoutDates.BlackoutDates.Add(
            new CalendarDateRange(new DateTime(2009, 8, 22), new DateTime(2009, 8, 23)));
        datePickerWithBlackoutDates.BlackoutDates.Add(
            new CalendarDateRange(new DateTime(2009, 8, 29), new DateTime(2009, 8, 30)));

        datePickerWithBlackoutDates.DateValidationError +=
            new EventHandler<DatePickerDateValidationErrorEventArgs>(DatePicker_DateValidationError);

        // root is a Panel that is defined elsewhere.
        spDatePicker.Children.Add(datePickerWithBlackoutDates);
CalendarDatePicker cdp=new CalendarDatePicker();
cdp.MinYear=DateTime.Now();
cdp.MaxYear=DateTime.AddYears(3)