summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WP8/ResourcesProvider.cs
blob: 3eaf2a1fa2c6adab506f0b62814ed33d49079327 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System.Windows.Controls;

namespace Xamarin.Forms.Platform.WinPhone
{
	internal class ResourcesProvider : ISystemResourcesProvider
	{
		ResourceDictionary _dictionary;

		public IResourceDictionary GetSystemResources()
		{
			_dictionary = new ResourceDictionary();

			UpdateStyles();

			return _dictionary;
		}

		Style GetListItemDetailTextStyle()
		{
			var result = new Style(typeof(Label));

			result.Setters.Add(new Setter { Property = Label.FontSizeProperty, Value = 32 });

			return result;
		}

		Style GetListItemTextStyle()
		{
			var result = new Style(typeof(Label));

			result.Setters.Add(new Setter { Property = Label.FontSizeProperty, Value = 48 });

			return result;
		}

		Style GetStyle(System.Windows.Style style, TextBlock hackbox)
		{
			hackbox.Style = style;

			var result = new Style(typeof(Label));
			result.Setters.Add(new Setter { Property = Label.FontFamilyProperty, Value = hackbox.FontFamily });

			result.Setters.Add(new Setter { Property = Label.FontSizeProperty, Value = hackbox.FontSize });

			return result;
		}

		void UpdateStyles()
		{
			var textBlock = new TextBlock();
			_dictionary[Device.Styles.TitleStyleKey] = GetStyle((System.Windows.Style)System.Windows.Application.Current.Resources["PhoneTextTitle1Style"], textBlock);
			_dictionary[Device.Styles.SubtitleStyleKey] = GetStyle((System.Windows.Style)System.Windows.Application.Current.Resources["PhoneTextTitle2Style"], textBlock);
			_dictionary[Device.Styles.BodyStyleKey] = GetStyle((System.Windows.Style)System.Windows.Application.Current.Resources["PhoneTextNormalStyle"], textBlock);
			_dictionary[Device.Styles.CaptionStyleKey] = GetStyle((System.Windows.Style)System.Windows.Application.Current.Resources["PhoneTextSmallStyle"], textBlock);
			_dictionary[Device.Styles.ListItemTextStyleKey] = GetListItemTextStyle();
			_dictionary[Device.Styles.ListItemDetailTextStyleKey] = GetListItemDetailTextStyle();
		}
	}
}