---
title: "Calendar Control in WPF"  
description: "A Calendar control in WPF is used to create a visual calendar in WPF through which users can pick date and raise an event on the selection of date. Th"  
author: "Anonymous User"  
published: 2011-04-02  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/528/calendar-control-in-wpf  
category: "wpf"  
tags: ["wpf"]  
reading_time: 3 minutes  

---

# Calendar Control in WPF

A [Calendar control](https://www.mindstick.com/articles/308/monthcalendar-control-in-vb-dot-net) in WPF is used to create a [visual](https://www.mindstick.com/articles/327169/major-advantage-to-use-visual-studio-code-in-2019-powerful-ide-used-by-most-of-the-developers) calendar in WPF through which [users](https://www.mindstick.com/news/2244/issue-preventing-users-from-accessing-facebook-s-social-networking-platforms-has-been-resolved) can pick date and raise an [event](https://www.mindstick.com/articles/167719/marquee-hire-benefits-of-event-lighting-hire-london) on the [selection](https://www.mindstick.com/blog/60/populate-records-in-second-listbox-according-to-the-selection-in-first-list-box) of date. The XAML <Calendar /> [elements](https://www.mindstick.com/forum/1440/wpf-button-with-multiple-text-elements) is used to create a calendar control in WPF. In this demonstration I will show you how to use calendar control in WPF.\

##### The following code snippet represents use of Calendar control in WPF

```
<Calendar Height="170" HorizontalAlignment="Left" Margin="149,66,0,0" Name="calendar1" VerticalAlignment="Top" Width="180" />
```

Width [property](https://www.mindstick.com/articles/198559/an-ownership-of-property-in-hua-hin) is used to set Width of the calendar control while Height property is used to set Height of the calendar control.

##### Output of the following code snippet is as follows

![Calendar Control in WPF](https://www.mindstick.com/mindstickarticle/47af6cd1-5ddd-4a9c-a862-27a90dd5da31/images/32ca4e58-0cf7-48ad-9f6a-41376d6f80e2.png)

The default view of the calendar control is show in figure. This is also known as Month view.

##### DisplayMode of a Calendar control

The DisplayMode property of a calendar control represents the format of display of calendar which can be month, year or decade. Month is default mode. In next to figure I will show you the year and decade mode of the calendar control.

![Calendar Control in WPF](https://www.mindstick.com/mindstickarticle/47af6cd1-5ddd-4a9c-a862-27a90dd5da31/images/3d72a795-5ecb-4542-aaf1-54b39ad09302.png)

Year view of the calendar control.

![Calendar Control in WPF](https://www.mindstick.com/mindstickarticle/47af6cd1-5ddd-4a9c-a862-27a90dd5da31/images/fcbde3e8-0cf8-430f-92b3-adfc7802357f.png)

Decade view of the calendar control.

##### SelectionMode property in Calendar control

The SelectionMode property of Calendar control represents way in which we select dates in Calendar control. There are 4 possible values of SelectionMode property.

##### Property:

- **None**— Means no selection are allowed.
- **SingleDate**— Means only a single date can be selected.
- **SingleRange**— Means single range of date can be selected.
- **MultipleRange**—Means non-contiguous range of date can be selected.

##### The following code snippet represents the SelectionMode property to Single Range.

```
<Calendar Height="170" HorizontalAlignment="Left" Margin="149,66,0,0" Name="calendar1" VerticalAlignment="Top" Width="180" SelectionMode="SingleRange" />
```

##### Output of the following code snippet is as follows

![Calendar Control in WPF](https://www.mindstick.com/mindstickarticle/47af6cd1-5ddd-4a9c-a862-27a90dd5da31/images/178df17c-6a43-4792-bd7e-206a528622d0.png)

##### BlackoutDates property in Calendar control

The Blackout [Dates](https://www.mindstick.com/forum/33698/function-to-generate-week-dates-for-a-given-year-in-sql-server) property in calendar control represents such types of dates which cannot be selected by users. All non selection dates are marked by cross.

##### The following code snippet represents use of BlackoutDates property in Calendar control

```
<Calendar Height="170" HorizontalAlignment="Left" Margin="149,66,0,0" Name="calendar1" VerticalAlignment="Top" Width="180" SelectionMode="SingleRange">            <Calendar.BlackoutDates>                <CalendarDateRange Start="2/1/2011" End="3/7/2011"/>                <CalendarDateRange Start="2/8/2011" End="3/8/2011"/>            </Calendar.BlackoutDates></Calendar>
```

##### The output of the following code snippet values are as follows

![Calendar Control in WPF](https://www.mindstick.com/mindstickarticle/47af6cd1-5ddd-4a9c-a862-27a90dd5da31/images/c531e977-902a-4d0d-9dfb-361a36b0c510.png)

##### Retrieving selected date from Calendar control

The following code snippet represents that how to retrieve Current date from Calendar control

```
<Calendar Height="170" HorizontalAlignment="Left" Margin="150,12,0,0" Name="calendar1" VerticalAlignment="Top" Width="180" SelectionMode="SingleRange">            <Calendar.BlackoutDates>            </Calendar.BlackoutDates>        </Calendar>        <TextBlock Height="23" HorizontalAlignment="Left" Margin="103,188,0,0" x:Name="txtSelectedDate" VerticalAlignment="Top" Width="337" />        <Button Content="Display Selected Date" Height="23" HorizontalAlignment="Left" Margin="103,228,0,0" x:Name="btnSelectedDate" VerticalAlignment="Top" Width="254" Click="btnSelectedDate_Click" />
```

##### Business logic to retrieve date from Calendar control

```
private void btnSelectedDate_Click(object sender,  RoutedEventArgs e){            DateTime date = (DateTime) calendar1.SelectedDate;            txtSelectedDate.Text = "Selected Date From Calendar Control  :  " + date.ToString();}
```

##### Output of above code snippet is as follows

![Calendar Control in WPF](https://www.mindstick.com/mindstickarticle/47af6cd1-5ddd-4a9c-a862-27a90dd5da31/images/b138dc17-0c72-4b52-9ce4-6cf1fcc2ece4.png)

---

Original Source: https://www.mindstick.com/articles/528/calendar-control-in-wpf

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
