使用Total的TimeSpan格式

时间:2016-11-18 10:29:56

标签: c# xaml xamarin

是否可以使用TimeSpan使用TotalHours格式化c#string.Format

我查看了documentation,但找不到任何内容。

我知道,我可以通过转换器(我正在使用Xamarin XAML)来实现,但是我希望我的应用程序能够在全球范围内使用,我不喜欢,这是要走的路。

实施例

在ViewModel中设置了类似的东西

public TimeSpan CurrentOutput {get; set;}

public ViewModel()
{
   CurrentOutput = new TimeSpan(1,2,3,4,5);
}

XAML代码中就像这样

<Label Text="{Binding CurrentOutput, StringFormat='{}{0:<total_hours>:mm}'}" />

1 个答案:

答案 0 :(得分:0)

不确定为什么你坚持不访问TotalHours,但万一你改变主意......

<Label Text = "{Binding CurrentOutput.TotalHours, StringFormat='{0:0}'}" />

或只是

<Label Text = "{Binding CurrentOutput.TotalHours}" />
相关问题