获取CalendarView当前选中的日期【UWP】【C#】

Obtain currently selected datein CalendarView [UWP] [C#]

在我的 UWP C# 应用程序中,我想在 TextBlock 中显示 CalendarView 的当前选定日期,我知道我应该使用 SelectedDatesChanged 事件来更新 TextBlock,但我找不到任何代码来获取和解析日期。

您可以使用 args.AddedDatesSelectedDatesChanged 事件中获取日期

private void CalendarView_SelectedDatesChanged(CalendarView sender, CalendarViewSelectedDatesChangedEventArgs args)
{
    var myDate = args.AddedDates.First();  //Since args.AddedDates returns collection we should use First to get the first item
    MyTextBlock.Text = myDate.ToString();  //You can convert DateTime into different format using myDate.ToString(format);
}

了解更多 Use patterns to format dates and times, DateTimeOffset.ToString Method