CalendarView SelectedDates 没有记录在我的 _DateChanged 方法中

CalendarView SelectedDates are not recorded in my _DateChanged method

...但这是我在单击按钮时执行操作的时候。

这不起作用:

XAML:

            <CalendarView CalendarViewDayItemChanging="MyCalendarView_DateChanged" x:Name="MyCalendarView" Grid.RowSpan="2" Grid.Row="1" Grid.Column="1" DisplayMode="Month" SelectionMode="Multiple" CalendarItemBackground="LightBlue" BorderBrush="Orange" BorderThickness="3" HorizontalAlignment="Center" VerticalAlignment="Center" />

C#:

private void MyCalendarView_DateChanged(Object sender, object e)
    {
        SelectedDate.Text = "The selected date(s):" + "\n";
        for (int i = 0; i <= MyCalendarView.SelectedDates.Count - 1; i++)
        {
            SelectedDate.Text += MyCalendarView.SelectedDates[i].ToString() + "\n";
        }


    }

但这确实有效:

XAML:

            <Button x:Name="GoButton" Click="GoButton_Click" Content="Go!" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right"   VerticalAlignment="Top"/>

C#:

private void GoButton_Click(object sender, RoutedEventArgs e)
    {
        SelectedDate.Text = "The selected date(s):" + "\n";
        for (int i = 0; i <= MyCalendarView.SelectedDates.Count - 1; i++)
        {
            SelectedDate.Text += MyCalendarView.SelectedDates[i].ToString() + "\n";
        }
    }

第一种方法有什么问题? SelectedDates 不应该自动刷新吗?

我宁愿避免使用按钮来记录用户的日期选择。

编辑

如果在第一种方法中我使用 RoutedEventArgs 而不是 Object 我会得到错误:

Severity Code Description Project File Line Suppression State Error CS0123 No overload for 'MyCalendarView_DateChanged' matches delegate 'TypedEventHandler'

如果您想监视日历视图控件 SelectedDates 集合依赖项 属性,您应该改为处理 SelectedDatesChanged 事件。

您已经正确地将 SelectionMode属性 更改为 Multiple,允许选择多个日期。为了跟踪选定日期的任何更新,您将在事件处理程序上为 SelectedDatesChanged 事件提供逻辑,而不是为 CalendarViewDayItemChanging,它用于访问单个日期项目和实例改变它的一些属性。