summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT.Tablet/WindowsResourcesProvider.cs
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2016-03-22 13:02:25 -0700
committerJason Smith <jason.smith@xamarin.com>2016-03-22 16:13:41 -0700
commit17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch)
treeb5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Platform.WinRT.Tablet/WindowsResourcesProvider.cs
downloadxamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip
Initial import
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT.Tablet/WindowsResourcesProvider.cs')
-rw-r--r--Xamarin.Forms.Platform.WinRT.Tablet/WindowsResourcesProvider.cs82
1 files changed, 82 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.WinRT.Tablet/WindowsResourcesProvider.cs b/Xamarin.Forms.Platform.WinRT.Tablet/WindowsResourcesProvider.cs
new file mode 100644
index 00000000..9c1351b0
--- /dev/null
+++ b/Xamarin.Forms.Platform.WinRT.Tablet/WindowsResourcesProvider.cs
@@ -0,0 +1,82 @@
+using System;
+using Windows.UI.Text;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+
+#if WINDOWS_UWP
+
+namespace Xamarin.Forms.Platform.UWP
+#else
+
+namespace Xamarin.Forms.Platform.WinRT
+#endif
+{
+ internal sealed class WindowsResourcesProvider : ISystemResourcesProvider
+ {
+ public IResourceDictionary GetSystemResources()
+ {
+ Windows.UI.Xaml.ResourceDictionary windowsResources = Windows.UI.Xaml.Application.Current.Resources;
+
+ var resources = new ResourceDictionary();
+ resources[Device.Styles.TitleStyleKey] = GetStyle("HeaderTextBlockStyle");
+ resources[Device.Styles.SubtitleStyleKey] = GetStyle("SubheaderTextBlockStyle");
+ resources[Device.Styles.BodyStyleKey] = GetStyle("BodyTextBlockStyle");
+ resources[Device.Styles.CaptionStyleKey] = GetStyle("CaptionTextBlockStyle");
+#if WINDOWS_UWP
+ resources[Device.Styles.ListItemTextStyleKey] = GetStyle("BaseTextBlockStyle");
+#else
+ resources[Device.Styles.ListItemTextStyleKey] = GetStyle("TitleTextBlockStyle");
+#endif
+ resources[Device.Styles.ListItemDetailTextStyleKey] = GetStyle("BodyTextBlockStyle");
+ return resources;
+ }
+
+ Style GetStyle(object nativeKey)
+ {
+ var style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources[nativeKey];
+
+ var formsStyle = new Style(typeof(Label));
+ foreach (SetterBase b in style.Setters)
+ {
+ var setter = b as Windows.UI.Xaml.Setter;
+ if (setter == null)
+ continue;
+
+ // TODO: Need to implement a stealth pass-through for things we don't support
+
+ if (setter.Property == TextBlock.FontSizeProperty)
+ formsStyle.Setters.Add(Label.FontSizeProperty, setter.Value);
+ else if (setter.Property == TextBlock.FontFamilyProperty)
+ formsStyle.Setters.Add(Label.FontFamilyProperty, setter.Value);
+ else if (setter.Property == TextBlock.FontWeightProperty)
+ formsStyle.Setters.Add(Label.FontAttributesProperty, ToAttributes(Convert.ToUInt16(setter.Value)));
+ else if (setter.Property == TextBlock.TextWrappingProperty)
+ formsStyle.Setters.Add(Label.LineBreakModeProperty, ToLineBreakMode((TextWrapping)setter.Value));
+ }
+
+ return formsStyle;
+ }
+
+ static FontAttributes ToAttributes(ushort uweight)
+ {
+ if (uweight == FontWeights.Bold.Weight || uweight == FontWeights.SemiBold.Weight || uweight == FontWeights.ExtraBold.Weight)
+ return FontAttributes.Bold;
+
+ return FontAttributes.None;
+ }
+
+ static LineBreakMode ToLineBreakMode(TextWrapping value)
+ {
+ switch (value)
+ {
+ case TextWrapping.Wrap:
+ return LineBreakMode.CharacterWrap;
+ case TextWrapping.WrapWholeWords:
+ return LineBreakMode.WordWrap;
+ default:
+ case TextWrapping.NoWrap:
+ return LineBreakMode.NoWrap;
+ }
+ }
+ }
+} \ No newline at end of file