Xaml 如果我想将2.01:30:00显示为49:30,Silverlight 5中合适的字符串格式是什么?

Xaml 如果我想将2.01:30:00显示为49:30,Silverlight 5中合适的字符串格式是什么?,xaml,silverlight-5.0,Xaml,Silverlight 5.0,如果我想将2.01:30:00显示为49:30,那么什么是合适的字符串格式?不是很优雅,但是这个C#可以工作: 因此,您必须编写一个转换器,它接受您的时间跨度并输出以下字符串: public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null) return null

如果我想将2.01:30:00显示为49:30,那么什么是合适的字符串格式?

不是很优雅,但是这个C#可以工作:

因此,您必须编写一个转换器,它接受您的时间跨度并输出以下字符串:

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value == null) return null;
        var time = (TimeSpan)value;
        return ((int)time.TotalHours).ToString() + ":" +
               ((int)(time.TotalMinutes - (int)time.TotalHours * 60)).ToString();
    }
然后在XAML中:

<TextBlock Text={Binding theTimeSpan, Converter={StaticResource TimeSpanConverter}} />

不是很优雅,但这款C#可以工作:

因此,您必须编写一个转换器,它接受您的时间跨度并输出以下字符串:

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value == null) return null;
        var time = (TimeSpan)value;
        return ((int)time.TotalHours).ToString() + ":" +
               ((int)(time.TotalMinutes - (int)time.TotalHours * 60)).ToString();
    }
然后在XAML中:

<TextBlock Text={Binding theTimeSpan, Converter={StaticResource TimeSpanConverter}} />


也许我只是一个noob,但我看不出您将2.01:30转换为49:00的转换逻辑是什么:30@Techmonk-这是一个2天1小时30分钟的时间跨度。也许我只是一个傻瓜,但我看不出你用什么翻译逻辑将2.01:30转换为49:30@Techmonk-时间跨度为2天,1小时30分钟。