Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DoubleToQuantityConverter.cs « Xamarin.PropertyEditing.Windows - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4797d87f34d45b47e6a3aa4448746b712846022e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Markup;

namespace Xamarin.PropertyEditing.Windows
{
	[ValueConversion (typeof (double), typeof (string))]
	internal class DoubleToQuantityConverter : MarkupExtension, IMultiValueConverter
	{
		public object Convert (object[] values, Type targetType, object parameter, CultureInfo culture)
		{
			var doubleValue = (double)values[0];
			var unit = (values.Length > 0 ? values[1] as string : "") ?? "";
			return $"{doubleValue:F0}{unit}";
		}

		public object[] ConvertBack (object value, Type[] targetTypes, object parameter, CultureInfo culture)
			=> throw new NotImplementedException ();

		public override object ProvideValue (IServiceProvider serviceProvider) => this;
	}
}