blob: 847d4b441c04b67a4be38d219d2cfe50434cbd30 (
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
|
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;
namespace Xamarin.PropertyEditing.Windows
{
[ValueConversion (typeof (double), typeof (double))]
internal class DoubleToPercentageConverter : MarkupExtension, IValueConverter
{
public object Convert (object value, Type targetType, object parameter, CultureInfo culture)
=> !(value is double doubleValue) ? DependencyProperty.UnsetValue
: doubleValue < 0 ? 0
: doubleValue > 1 ? 100
: doubleValue * 100;
public object ConvertBack (object value, Type targetType, object parameter, CultureInfo culture)
=> !(value is double doubleValue) ? DependencyProperty.UnsetValue
: doubleValue < 0 ? 0
: doubleValue > 100 ? 1
: doubleValue / 100;
public override object ProvideValue (IServiceProvider serviceProvider) => this;
}
}
|