And We use the HasValue property on the nullable type to determine whether the inner DateTime exists or not.
Then We get a reference to the DateTime indicated by the Calendar at this point. We call ToShortDateString on it.
Example markup, XAML:
Title="MainWindow" Height="350" Width="525">
/// Interaction logic for MainWindow.xaml
public partial class MainWindow : Window
private void Calendar_SelectedDatesChanged(object sender,
// ... Get reference.
var calendar = sender as Calendar;
// ... See if a date is selected.
// ... Display SelectedDate in Title.
DateTime date = calendar.SelectedDate.Value;
this.Title = date.ToShortDateString();
Summary. The Calendar control displays a month-based calendar. One important event is SelectedDatesChanged—with it, we can detect when the user selects a day within the control.
Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.
This page was last updated on Sep 27, 2022 (edit).