Using the Calendar control in your application
The Calendar
control, part of the System.Windows.Controls
namespace, allows you to create a visual calendar in WPF applications. It allows you to select a date or a collection of dates. As it inherits from the Control
class, all common properties and events from Control
class are available to it.
In this recipe, we will learn more about Calendar
control and how to use that.
Getting ready
To get started with this recipe, let's create a WPF application project named CH02.CalendarDemo
.
How to do it...
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...