This project has moved. For the latest updates, please go here.

MaskedTextBox and DateTime value?

Jul 1, 2011 at 12:00 PM

Hi there,

I stumbled upon a problem with MaskedTextBox which is databound to a DateTime variable.

When I set the mask property as below, the masked textbox doesn't display the bound DateTime, even when I just return "TestDate.Date"

<Controls:MaskedTextBox Value="{Binding TestDate}"
                                    IncludeLiterals="True"
                                    ValueType="{x:Type System:DateTime}"
                                    Mask="00/00/0000" />

When setting the mask to "00/00/0000 00:00:00" , I get a display of the date part and the time is 00:00:00. Which is correct, as I just return the date part from the variable.

 

Question: How can I use the masked text box to just display the date part, using a DateTime binding ?

Jul 1, 2011 at 1:58 PM

The MaskedTextProvider class that I am using does not work properly with DateTime.  I suggest using the DateTimeUpDown control and using a custom format to support your requirement.  And yes, you can hide the button spinners if you don't want to see them.