30 lines
739 B
C#
30 lines
739 B
C#
using Microsoft.UI.Xaml.Data;
|
|
using System;
|
|
|
|
namespace Harmonia.WinUI.Converters;
|
|
|
|
public sealed partial class SecondsToStringConverter : IValueConverter
|
|
{
|
|
public SecondsToStringConverter()
|
|
{
|
|
|
|
}
|
|
|
|
public object? Convert(object value, Type targetType, object parameter, string language)
|
|
{
|
|
if (value is not double doubleValue)
|
|
return null;
|
|
|
|
TimeSpan timeSpan = TimeSpan.FromSeconds(doubleValue);
|
|
|
|
if (timeSpan.Hours >= 1)
|
|
return timeSpan.ToString(@"%h\:mm\:ss");
|
|
|
|
return timeSpan.ToString(@"%m\:ss");
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
|
{
|
|
return TimeSpan.Parse((string)value);
|
|
}
|
|
} |