Follow these steps to add the basic controls to the main window:
- Open the MainWindow.xaml page.
- Inside the default Grid panel, add the tag <Calendar /> to create the basic calendar control in the application UI.
- To retrieve the date selected by the user, register the SelectedDatesChanged event to it, as shown in the following code snippet:
<Grid Margin="10"> <Calendar SelectedDatesChanged="OnSelectedDateChanged" HorizontalAlignment="Left" /> </Grid>
- Add the associated event handler (OnSelectedDateChanged) in the code-behind class (MainWindow.xaml.cs), as shown in the following code, to retrieve the selected date and show it in a message box:
private void OnSelectedDateChanged(object sender, SelectionChangedEventArgs e) { MessageBox.Show("You selected: " + ((DateTime)e.AddedItems[0]).ToString("dd-MMM-yyyy")); }
- Let's run the application. You will see the...