Custom DateTime stringformat in WPF
binding, datetime, string-formatting, wpf
Solution
`ContentControls` have a `ContentStringFormat` property which overrides the original formatting.
(When i saw your question i expected this to be the problem actually but was surprised to find a `TextBlock` at first)
Problem
I can't get my custom DateTime string format to work in my binding. I want the format to be "mmmm, yyyy" (e.g. "June, 2012"). The following does not work. I get a short date format (m/d/yyyy). ``` <TextBlock Text="{Binding ElementName=ThisWindow, Path=Date, StringFormat={}{0:MMMM\, yyyy}"/> ``` I've considered using a converter, but I prefer a pure XAML approach. Edit: For clarity, I have a `Window` with a dependency property `Date` of type `DateTime`. In my XAML, I've named the window 'Thiswindow'. Edit 2: I looked back at my actual code, and I had a `Label`, not a `TextBlock`. I changed it to TextBlock and it works fine. ``` <Label Content="{Binding ElementName=ThisWindow, Path=Date, StringFormat={}{0:MMMM\, yyyy}"/> ``` Anyone know why it doesn't work with `Label`? Thanks.