How to get value from UPP DatePicker control?

I use a couple of DatePickers in my UWP application and don’t know how to get the current value from it. Is there an easy way to do this?

+5
source share
2 answers

The property you are looking for is Date.

If you have your DatePicker in your XAML, like this

<DatePicker x:Name="DatePicker" /> 

And want to access the date in the code, you can do it like this

 var date = this.DatePicker.Date; 

You can also listen for a DateChanged event like this

 this.DatePicker.DateChanged += (o, e) => { var changedDate = e.NewDate; }; 
+6
source

Date element is not a DateTime

so suppose datePicker1 is your datePicker,

 <DatePicker x:Name="datePicker11" /> 

you can get the selected value as follows:

 DateTime firstDate = datePicker1.Date.DateTime; 
+1
source

Source: https://habr.com/ru/post/1260028/


All Articles