blob: 3bf8d20ee7b666ea587145ba820f2e5cbbfc20cb (
plain)
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
|
using System;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
namespace MaterialDesignThemes.Wpf.Converters
{
public class RangeLengthConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values == null || values.Length != 4 || values.Any(v => v == null))
return Binding.DoNothing;
if (!double.TryParse(values[0].ToString(), out double min)
|| !double.TryParse(values[1].ToString(), out double max)
|| !double.TryParse(values[2].ToString(), out double value)
|| !double.TryParse(values[3].ToString(), out double containerLength))
return Binding.DoNothing;
var percent = (value - min) / (max - min);
var length = percent * containerLength;
return length > containerLength ? containerLength : length;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
|