简体   繁体   English

使用SelectedDate添加到BlackoutDate

[英]Adding to BlackoutDates using SelectedDate

A small demo program is included below. 下面包括一个小型演示程序。 To reproduce the problem, select a date and click the "BlackoutDate" button. 要重现该问题,请选择一个日期,然后单击“ BlackoutDate”按钮。 On my system I get an ArgumentOutOfRange exception. 在我的系统上,我收到ArgumentOutOfRange异常。

Any suggestions on how to fix this? 对于如何解决这个问题,有任何的建议吗?

XAML: XAML:

<Window x:Class="CalendarBlackoutDate.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <StackPanel>
        <Calendar Name="calendar"/>
        <Button Name="blackoutDateButton" Content="BlackoutDate" Click="blackoutDateButton_Click"/>
    </StackPanel>
</Window>

C#: C#:

using System.Windows;
using System.Windows.Controls;

namespace CalendarBlackoutDate
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void blackoutDateButton_Click(object sender, RoutedEventArgs e)
        {
            calendar.BlackoutDates.Add(
                new CalendarDateRange(
                    calendar.SelectedDate.Value));
        }
    }
}

Same calendar for the selected date as the blackout?? 所选日期的日历与停电时间相同? Selected date cannot be blackout date. 所选日期不能为停电日期。

 calendar1.BlackoutDates.Add(
            new CalendarDateRange(
                calendar2.SelectedDate.Value));

<Calendar Name="calendar1"/>
<Calendar Name="calendar2"/>

If one calendar 如果一个日历

if (calendar1.SelectedDate == null) return;
DateTime dtBO = (DateTime)calendar1.SelectedDate;
calendar1.SelectedDate = null;
calendar1.BlackoutDates.Add(new CalendarDateRange(dtBO));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM