Search This Blog

Friday, October 26, 2018

DatePicker WPF Example

System.Windows.Controls -> DatePicker

Represents a control that allows the user to select a date.

Example


<Window x:Class="WpfApp4.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid>
        <DatePicker HorizontalAlignment="Left" Margin="225,118,0,0" VerticalAlignment="Top" SelectedDateChanged="DatePicker_SelectedDateChanged"/>
    </Grid>
</Window>

private void DatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
{
  var datePicker = sender as DatePicker;
  MessageBox.Show(datePicker.SelectedDate.ToString());
}