下面包含一个小型演示程序。要重现该问题,请选择日期并单击“BlackoutDate”按钮。在我的系统上,我得到ArgumentOutOfRange
例外。
有关如何解决此问题的任何建议吗?
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#:
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));
}
}
}
答案 0 :(得分:1)
所选日期与停电相同的日历?所选日期不能是限制日期。
calendar1.BlackoutDates.Add(
new CalendarDateRange(
calendar2.SelectedDate.Value));
<Calendar Name="calendar1"/>
<Calendar Name="calendar2"/>
如果有一个日历
if (calendar1.SelectedDate == null) return;
DateTime dtBO = (DateTime)calendar1.SelectedDate;
calendar1.SelectedDate = null;
calendar1.BlackoutDates.Add(new CalendarDateRange(dtBO));