I have a windows phone 7 application where I´m using a “DatePicker” from the silverlight toolbox.
I´m trying to save the choosen DatePicker value, as suggestion I assign it to an DateTime structure so that I later can populate the same DatePicker with the saved DateTime value. Simple as it sounds, I don´t get it to work due to an error:
Cannot implicitly convert type ‘System.DateTime?’ to ‘System.DateTime’. An explicit conversion exists (are you missing a cast?)
when constructing the DateTime value as below:
DateTime saved = datePicker.Value;
The DateTime are to be saved for later use as following:
datePicker.Value = saved.Value;
Does the DatePicker not have a valid DateTime value? I´m new at this, what shall I do?
The Datepicker Value property is a
Nullable<DateTime>(same asDateTime?). This is so it can represent “nothing chosen”. (DateTime is a struct, so it can not be null). Can you store aNullable<DateTime>instead? Otherwise, you can test if theNullable<DateTime>has a value: