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.
Drag a DatePicker from the toolbox. The following example shows how to create a DatePicker control. When you click on any date from the DatePicker control, the program will update the title with that date. The following XAML code creates a DatePicker with some properties and click event.
The DatePicker control allows the user to select a date by either typing it into a text field or by using a drop-down Calendar control. Many of a DatePicker control's properties are for managing its built-in Calendar, and function identically to the equivalent property in Calendar.
Set the DisplayMode property to Month, Year, or Decade. Specify whether the user can select a date, a range of dates, or multiple ranges of dates. Use the SelectionMode. Specify the range of dates that the Calendar displays.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With