I often use textboxes in my wpf-projects which are bound to datetime-propertys. I want to format the dates into the german format dd.MM.yyyy
.
Currently I do this with a self-written converter, which I can give the needed dateformat.
For example like this:
<TextBox Name="Date" Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type prj:MyBar}}, Path=Date, Converter={StaticResource dateConverter}, ConverterParameter=dd.MM.yyyy}" />
The only thing the converter does, is to call the ToString(string formatString)
-method of DateTime.
Is there a 'smarter' way to format a date with data-binding. The best would be if there is no need to write C#-code. Perhaps there is any existing class in the microsoft-libs, that could do such date-conversion for data-binding, but I did not found it yet.
Would be great if there are any advices,
greetings, Martin