forked from polyv/csharp-vod-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ValueConverters.cs
34 lines (30 loc) · 1.12 KB
/
ValueConverters.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using 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 PolyvPlayerDemoWinform
{
public class TimeSpanToSecondsConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
if (value is TimeSpan) return ((TimeSpan)value).TotalSeconds;
if (value is Duration) return ((Duration)value).HasTimeSpan ? ((Duration)value).TimeSpan.TotalSeconds : 0d;
return 0d;
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
var result = TimeSpan.FromTicks((long)(TimeSpan.TicksPerSecond * (double)value));
// Do the conversion from visibility to bool
if (targetType == typeof(TimeSpan)) return result;
if (targetType == typeof(Duration)) return new Duration(result);
return Activator.CreateInstance(targetType);
}
}
}