Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在wpf(数据网格)中格式化时间跨度?_C#_Wpf_Datagrid_Format_Timestamp - Fatal编程技术网

C# 如何在wpf(数据网格)中格式化时间跨度?

C# 如何在wpf(数据网格)中格式化时间跨度?,c#,wpf,datagrid,format,timestamp,C#,Wpf,Datagrid,Format,Timestamp,我将TimeSpan以ticks的形式保存到SqlCe中,当我在DataGrid中加载数据时,我希望将该值格式化为HH:MM:SS。我试着用这个: <DataGridTextColumn Binding="{Binding tiempo, StringFormat={}{0:hh':'mm':'ss}, TargetNullValue=' --- '}" Width="80" Header="Tiempo"/> 但DataGrid显示的是“hh:mm:ss”,而不是值 我还尝

我将TimeSpan以ticks的形式保存到SqlCe中,当我在DataGrid中加载数据时,我希望将该值格式化为HH:MM:SS。我试着用这个:

<DataGridTextColumn Binding="{Binding tiempo, StringFormat={}{0:hh':'mm':'ss}, TargetNullValue=' --- '}"  Width="80" Header="Tiempo"/>

但DataGrid显示的是“hh:mm:ss”,而不是值

我还尝试使用其他模式,如
StringFormat=“hh \:mm \:ss”

有什么想法吗


谢谢!对不起,我的英语不好

你可以用双反斜杠这样写:

<DataGridTextColumn Binding="{Binding tiempo, StringFormat=hh\\:mm\\:ss}"/>
<DataGridTextColumn>
    <DataGridTextColumn.Binding>
        <Binding Path="tiempo" StringFormat="hh\:mm\:ss"/>
    </DataGridTextColumn.Binding>
</DataGridTextColumn>

或者像这样使用单个反斜杠:

<DataGridTextColumn Binding="{Binding tiempo, StringFormat=hh\\:mm\\:ss}"/>
<DataGridTextColumn>
    <DataGridTextColumn.Binding>
        <Binding Path="tiempo" StringFormat="hh\:mm\:ss"/>
    </DataGridTextColumn.Binding>
</DataGridTextColumn>

虽然这已经是默认格式,但是

<DataGridTextColumn Binding="{Binding tiempo}"/>

应该也可以


有关更多示例,请参见。

我解决了这个问题!在数据库中,我像bigint一样存储“tiempo”,所以我将其更改为nvarchar,并对其进行了一些修复。
谢谢大家

不确定是否可以在绑定中使用
String.Format
。但您可以通过使用
值转换器
轻松实现这一点。看看这个@programmer93,这是属性,不是String.Format method.mm。同样的结果,datagrid显示hh:mm:ss,但不是格式化的值。我甚至用DataGridTextColumn尝试过,它对我有效。您能否显示
tiempo
属性的声明?