TMusic/Converters/TimeSpanToSecondsConverter.cs
(完整代码) 1KBusing System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
namespace TMusic.Converters
{
public class TimeSpanToSecondsConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
switch (value)
{
case TimeSpan span:
return span.TotalSeconds;
case Duration duration:
return duration.HasTimeSpan ? duration.TimeSpan.TotalSeconds : 0d;
default:
return 0d;
}
}
/// <inheritdoc />
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is double == false) return 0d;
var result = TimeSpan.FromTicks(System.Convert.ToInt64(TimeSpan.TicksPerSecond * (double)value));
// Do the conversion from visibility to bool
if (targetType == typeof(TimeSpan)) return result;
return targetType == typeof(Duration) ? new Duration(result) : Activator.CreateInstance(targetType);
}
}
}
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
