Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
4155
XamDateTimeInput Validation and Reverting Value or Displaying Error
posted

Hello,

I have a XamDateTimeInput.  Its value controls whether or not an action can be applied.  I would like to only be able to apply the action IF the DateTime from the input is valid.  I have played with setting different InvalidValueBehaviors, but none really do what i want.  For example, if i highlight the date in the control and press delete, the XamDateTimeInput turns red to tell me that it is not a valid date.  However, the Date i have bound to it is not updated and stays with the original value.  This lets my Apply button function, even though, to the user, it LOOKS like there is an invalid date.  This is with the InvalidValueBehavior set to "Default".  Also, if i manually type 02/31/2013 (an invalid date) and then click Apply, i see the error pop up stating the date is not valid.  But if i hit enter again, the date has become 2/3/2013, and is therefore a valid date.  I tried changing InvalidValueBehavior to "Revert Value" and this doesn't quite work either.  If i type 2/31/2013, the value is reverted, allowing my Apply method.  But if i hit "delete" after highlighting the entry, it appears to the user there is no date but the underlying data is still a valid date, and Apply is able to happen.  How can i keep the display of the control and the bound property in harmony and keep the user from getting confused about all this?  I included a sample project that illustrates this simply.  You may need to change the InvalidValueBehavior to see what each scenario does.

WpfApplication1.zip