I need to reformat a string containing a date without using code behind. The string is in the form YY/MM/DD but needs to be MM/DD/YYYY. I have seen this done given a Date object, however I am limited because it is a string.
So far it seems that I need code behind to do this but at the moment that is unsupported from our vendor.
Since the question was asked about XAML-only string formatting, here is how you would specifiy the
StringFormatin your XAML:Simple:
Longhand: (note the escape curly brackets)
Custom: (added text)
A whole
TextBoxusing aStringFormat:The syntax is the same as String.Format; however:
All that being said, what you are trying to do is not simply format a date, but rather you are trying to parse a string as a
DateTime, then format thatDateTimeas a string. Of those two steps, only the later can be done in XAML. It’s sad times, but after all, XAML is for markup, not computation.On the bright side, if you have the ability to reference another assembly in your project, you can implement an
IValueConverter, which will give you the ability to convert the input string to aDateTime, then the StringFormat in XAML would work. Alternatively, yourIValueConvertercould just export the date in the specified format.