---
title: "DatePicker control in WPF"  
description: "We can use DatePicker control in WPF to select an appropriate date. In XAML DatePicker  element is used to create a DatePicker control. In this demons"  
author: "Anonymous User"  
published: 2011-04-08  
updated: 2019-12-23  
canonical: https://www.mindstick.com/articles/541/datepicker-control-in-wpf  
category: "wpf"  
tags: ["wpf"]  
reading_time: 2 minutes  

---

# DatePicker control in WPF

We can use DatePicker control in WPF to select an appropriate date. In XAML <DatePicker /> element is used to create a DatePicker control. In this demonstration we learn how to use DatePicker control in WPF.\

##### Some major properties related with DatePicker control

- **BlackoutDates**—BlackoutDate property is used to cross the date in date picker control which is not accessible by user for selected.
- **DisplayDate**—DisplayDate property is used to set date on control which is shown when DatePicker control is launch in application. By default it is the current date of the system.
- **FirstDayOfWeak**—FirstDayOfWeak property represents first day of month in date picker control.
- **SelectedDate**—SelectedDate property is used to retrieve selected date of date picker control.
- **SelectedDateFormat**—SelectedDateFormat property is used to change display date format.

##### The following XAML code snippet create a UI of DatePicker control demo

```
<Grid>        <DatePicker Height="25" HorizontalAlignment="Left" Margin="140,70,0,0" Name="datePicker1" VerticalAlignment="Top" Width="163" SelectedDateFormat="Long" />        <Button Content="Get Selected Date" Height="23" HorizontalAlignment="Left" Margin="140,143,0,0" x:Name="btnSelectDate" VerticalAlignment="Top" Width="163" Click="btn_click" /></Grid>
```

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

![DatePicker control in WPF](https://www.mindstick.com/mindstickarticle/454a2e37-a58a-4ecc-bd0e-bff1ba3690d1/images/2624ec9a-15db-46ef-a86c-87a48bba6f0b.png)

When user click on calendar icon then a calendar is open and user can select an appropriate date. After selecting date when user click on Get Selected Date button then selected date will be shown in message box.

##### Code at the click event of Get Selected Date

```
private void btn_click(object sender,  RoutedEventArgs e){            MessageBox.Show(datePicker1.SelectedDate.Value.ToString());} 
```

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

![DatePicker control in WPF](https://www.mindstick.com/mindstickarticle/454a2e37-a58a-4ecc-bd0e-bff1ba3690d1/images/80e21fc8-0442-4a9b-9b20-0271328a31d5.png)

![DatePicker control in WPF](https://www.mindstick.com/mindstickarticle/454a2e37-a58a-4ecc-bd0e-bff1ba3690d1/images/74adfeca-e1c9-4db2-a9a7-6d728a89a104.png)

![DatePicker control in WPF](https://www.mindstick.com/mindstickarticle/454a2e37-a58a-4ecc-bd0e-bff1ba3690d1/images/2e092ce9-f07a-48fd-af92-fbd05011e603.png)

---

Original Source: https://www.mindstick.com/articles/541/datepicker-control-in-wpf

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
