summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WP8/TextAlignmentToHorizontalAlignmentConverter.cs
blob: 7f8aeef65f97e1145b3c053f6fe41f48ccadcae3 (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
34
35
36
37
38
39
40
41
42
43
using System;
using System.Globalization;
using System.Windows;

namespace Xamarin.Forms.Platform.WinPhone
{
	public sealed class TextAlignmentToHorizontalAlignmentConverter : System.Windows.Data.IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
		{
			var alignment = (System.Windows.TextAlignment)value;

			switch (alignment)
			{
				case System.Windows.TextAlignment.Center:
					return HorizontalAlignment.Center;
				case System.Windows.TextAlignment.Left:
					return HorizontalAlignment.Left;
				case System.Windows.TextAlignment.Right:
					return HorizontalAlignment.Right;
				default:
					return HorizontalAlignment.Left;
			}
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
		{
			var alignment = (HorizontalAlignment)value;

			switch (alignment)
			{
				case HorizontalAlignment.Left:
					return System.Windows.TextAlignment.Left;
				case HorizontalAlignment.Center:
					return System.Windows.TextAlignment.Center;
				case HorizontalAlignment.Right:
					return System.Windows.TextAlignment.Right;
				default:
					return System.Windows.TextAlignment.Left;
			}
		}
	}
}