Reputation: 925
I had a TimeSpan saved into SqlCe in ticks, and when i load the data in a DataGrid i want to format this value in HH:MM:SS. I try it with this:
<DataGridTextColumn Binding="{Binding tiempo, StringFormat={}{0:hh':'mm':'ss}, TargetNullValue=' --- '}" Width="80" Header="Tiempo"/>
But the DataGrid shows 'hh:mm:ss' instead of the value.
i try also try it with other patterns like StringFormat="hh\:mm\:ss"
Any idea?
Thanks! and sorry for my bad english!
Upvotes: 3
Views: 4723
Reputation: 925
i solved the problem! in database i was storing "tiempo" like bigint, so i changed it to nvarchar and making a few fixes it works. thanks for all!
Upvotes: 0
Reputation: 128062
You could write it like this with double backslashes:
<DataGridTextColumn Binding="{Binding tiempo, StringFormat=hh\\:mm\\:ss}"/>
or like this with single backslashes:
<DataGridTextColumn>
<DataGridTextColumn.Binding>
<Binding Path="tiempo" StringFormat="hh\:mm\:ss"/>
</DataGridTextColumn.Binding>
</DataGridTextColumn>
although that is already the default formatting, so
<DataGridTextColumn Binding="{Binding tiempo}"/>
should also be ok.
See also this answer for a few more examples.
Upvotes: 5