Quantcast
Channel: Editors for WPF - Recent Posts
Viewing all articles
Browse latest Browse all 942

DateTimeEditBox: Format property behaves differently from DateTime.ToString( format )

$
0
0

Hello guys,

In our application, a user can define a date time format that is used for both display and edit.

In display scenario, we use DateTime.ToString( format )

In edit scenario, we set DateTimeEditBox.Format = format

We start to notice inconsistent behaviors when format contains escaped symbols in literal:

 

E.g. (presuming current culture is En-AU)


1. DateTime behavior:

Code:

DateTime.Now.ToString(@"dd-MM-yyyy 'my \'special\' date'")

 

Output:

25-07-2013 my 'special' date

 

2. DateTimeEditBox behavior:

Code:

<editors:DateTimeEditBox x:Name="editBox"
                                     Width="200"
                                     Margin="0,7,0,0"
                                     HorizontalAlignment="Left"
                                     Format="dd-MM-yyyy 'a \'special\' date'"
                                     Value="{x:Static system:DateTime.Today}"><editors:DateTimeEditBox.LayoutTransform><ScaleTransform ScaleX="{Binding ElementName=scaleSlider, Path=Value}" ScaleY="{Binding ElementName=scaleSlider, Path=Value}" /></editors:DateTimeEditBox.LayoutTransform></editors:DateTimeEditBox>

 

DateTimeEditBox.DateValue binds to DateTime.Now

Output:

25-07-2013 a \0pecial' 25aAe'

Note how the first backslash is treated as a literal character rather than an escape character, and that the first escaped single quote is treated as a closing quote rather than a literal.

 

Is this a problem in DateTimeEditBox formatting?


Viewing all articles
Browse latest Browse all 942

Trending Articles