【问题标题】:Block dates in windows apps在 Windows 应用程序中阻止日期
【发布时间】:2015-12-06 20:23:51
【问题描述】:

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

我收到了使用“DisplayDateStart”、“DisplaydateEnd”的建议,但是当我使用它们时出现错误 - “DatePicker 不包含 DisplayDateStart 的定义,并且没有可以找到接受 DatePicker 类型的第一个参数的扩展方法 DisplaydateStart”。

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

XAML:

<StackPanel x:Name="spDatePicker">

</StackPanel>

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);

非常感谢您的帮助。 谢谢 饶

【问题讨论】:

    标签: c# windows xaml datepicker


    【解决方案1】:

    使用日历日期选择器,您正在查看的 wpf 控件与 Windows 商店 api 的功能不完全一致。 https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.calendardatepicker.mindate.aspx

    根据Setting Mindate and MaxDate for Datepicker Control

    CalendarDatePicker cdp=new CalendarDatePicker();
    cdp.MinYear=DateTime.Now();
    cdp.MaxYear=DateTime.AddYears(3)
    

    【讨论】:

    • 嗨,我试过了,但它说找不到“CalendarDatePicker”
    • 我刚刚生成了一个新的商店项目,添加了一个按钮并将第一行添加到其中,工作正常。 MinYear 不存在,您需要 MinDate (形成我在上面发布的网址)。确保在您的文件顶部有以下导入: using Windows.UI.Xaml.Controls;
    • ugh.. 抱歉,我刚刚意识到我将其作为 Windows 应用商店阅读,您正在做 desktop 来澄清,对吗?不存储?从桌面 WPF 应用程序的角度来看,您的代码在我的系统上使用新的 WPF 应用程序编译得很好。具体来说 - 您正在创建哪种应用类型?
    • 嗨 Adam,我创建了一个通用应用程序 App (Windows 8.1)。我不确定这是否是 WPF。我对 Windows 开发很陌生
    • 对不起,我想我提到了商店应用程序,但它是 windows 应用程序。
    猜你喜欢
    • 1970-01-01
    • 2012-12-07
    • 1970-01-01
    • 1970-01-01
    • 2012-07-12
    • 2011-11-28
    • 2015-04-21
    • 2020-12-13
    • 1970-01-01
    相关资源
    最近更新 更多