下面包含一个小型演示程序。要重现该问题,请选择一个日期并单击“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));
}
}
}