简体   繁体   中英

How do I get value from DatePicker(WPF) in C#?

I have a DatePicker class in my program, but how do I get an actual value, such as 19.12.2017, from it? I've tried to apply the way that is used to get the value from DateTimePicker in WinForms but it didn't work.

You get the selected value from the SelectedDate property of the DatePicker.

<DatePicker x:Name="dp" />

DateTime? selectedDate = dp.SelectedDate;
if(selectedDate.HasValue)
{
    string formatted = selectedDate.Value.ToString("dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM