summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WP8/Converters/ColorConverter.cs
blob: 1e495ecffc0288dccaad84512d474787da1b3b21 (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
using System;
using System.Globalization;
using System.Windows.Media;

namespace Xamarin.Forms.Platform.WinPhone
{
	public class ColorConverter : System.Windows.Data.IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			var color = (Color)value;
			var defaultColorKey = (string)parameter;

			Brush defaultBrush = defaultColorKey != null ? (Brush)System.Windows.Application.Current.Resources[defaultColorKey] : new SolidColorBrush(Colors.Transparent);

			return color == Color.Default ? defaultBrush : color.ToBrush();
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			throw new NotSupportedException();
		}
	}
}