I really broke my mind by trying to find how to format string when you are using DataGridTemplates:
<DataGridTemplateColumn Header="DEMOB. DATE">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate >
<DatePicker SelectedDate="{Binding DemobDate,
Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,StringFormat='{}{0:dd/MMM/yy}'}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
For some reasons XAML code above not working when I use DataGridTemplates. Can someone please explain me where i did wrong.
P.S.
Evrything is works when I use:
<DataGridTextColumn Header="DEMOB. DATE" Binding="{Binding DemobDate, StringFormat='{}{0:dd/MMM/yyyy}',Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Width="90"/>
But I really need to have DatePicker in the cell, and as far as i understood my only option to have a DatePicker in the cell is to use DataGridTemplateColumn, and that where StringFormat option for some reason ignored.
Thanks, Maks!
Binding.StringFormatis ignored unless the target property is of typeString. That's whyContentControl(hence its descendantsLabeletc.) has aContentStringFormatproperty: BecauseContentControl.Contentis Object. Likewise,DatePicker.SelectedDateis naturally not a string. You'll find duplicates of this question aboutLabeland other ContentControl descendants.SelectedDateFormat="Short".