Assign a null value to DateTime property
-
I am developing a MVVM application using C#. I have a property called 'ReportedDate' of type DateTime which is optional in database field. In my view I have bound 'ReportedDate' property to txtReportedDate text box. After getting data from database, if there is no value in ReportedDate field, I want to display blank in txtReportedDate text box. But empty values cannot be assign to the property 'ReportedDate' in ViewModel. It gives errors. How can I do this?
-
I am developing a MVVM application using C#. I have a property called 'ReportedDate' of type DateTime which is optional in database field. In my view I have bound 'ReportedDate' property to txtReportedDate text box. After getting data from database, if there is no value in ReportedDate field, I want to display blank in txtReportedDate text box. But empty values cannot be assign to the property 'ReportedDate' in ViewModel. It gives errors. How can I do this?
By itself, a DateTime cannot be null. To make it a nullable type, use DateTime?
Chill _Maxxx_
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier -
I am developing a MVVM application using C#. I have a property called 'ReportedDate' of type DateTime which is optional in database field. In my view I have bound 'ReportedDate' property to txtReportedDate text box. After getting data from database, if there is no value in ReportedDate field, I want to display blank in txtReportedDate text box. But empty values cannot be assign to the property 'ReportedDate' in ViewModel. It gives errors. How can I do this?
You might need a value converter as well to box and unbox the nullable DateTime. The framework will not directly cast DateTime? to DateTime.
-
You might need a value converter as well to box and unbox the nullable DateTime. The framework will not directly cast DateTime? to DateTime.
-
By itself, a DateTime cannot be null. To make it a nullable type, use DateTime?
Chill _Maxxx_
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier -
I already showed you. The question mark after the type made it nullable.
Chill _Maxxx_
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier -
I am developing a MVVM application using C#. I have a property called 'ReportedDate' of type DateTime which is optional in database field. In my view I have bound 'ReportedDate' property to txtReportedDate text box. After getting data from database, if there is no value in ReportedDate field, I want to display blank in txtReportedDate text box. But empty values cannot be assign to the property 'ReportedDate' in ViewModel. It gives errors. How can I do this?