diff options
author | Neil McAlister <pingzing@users.noreply.github.com> | 2016-09-30 21:47:41 +0300 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-09-30 11:47:41 -0700 |
commit | c07c2314f5737d480088319e87ab299b22cb4ddc (patch) | |
tree | f929ed0c594d3e53fcdfb0dd9e0151f2f940d962 /Xamarin.Forms.Platform.WinRT.Phone | |
parent | bd195ffe10e713393b9eaaff4f0720227e3ea9c9 (diff) | |
download | xamarin-forms-c07c2314f5737d480088319e87ab299b22cb4ddc.tar.gz xamarin-forms-c07c2314f5737d480088319e87ab299b22cb4ddc.tar.bz2 xamarin-forms-c07c2314f5737d480088319e87ab299b22cb4ddc.zip |
[Windows] Fix Device Style inheritance (#324)
* Make Device Styles get Style Setters from ancestor styles
* Fix parentheses to match style
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT.Phone')
-rw-r--r-- | Xamarin.Forms.Platform.WinRT.Phone/WindowsPhoneResourcesProvider.cs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.WinRT.Phone/WindowsPhoneResourcesProvider.cs b/Xamarin.Forms.Platform.WinRT.Phone/WindowsPhoneResourcesProvider.cs index a4ae4e94..adbe7dea 100644 --- a/Xamarin.Forms.Platform.WinRT.Phone/WindowsPhoneResourcesProvider.cs +++ b/Xamarin.Forms.Platform.WinRT.Phone/WindowsPhoneResourcesProvider.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using Windows.UI.Text; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; @@ -25,6 +27,7 @@ namespace Xamarin.Forms.Platform.WinRT Style GetStyle (object nativeKey) { var style = (Windows.UI.Xaml.Style) Windows.UI.Xaml.Application.Current.Resources[nativeKey]; + style = GetAncestorSetters(style); var formsStyle = new Style (typeof (Label)); foreach (var b in style.Setters) { @@ -47,6 +50,48 @@ namespace Xamarin.Forms.Platform.WinRT return formsStyle; } + static Windows.UI.Xaml.Style GetAncestorSetters (Windows.UI.Xaml.Style value) + { + var style = new Windows.UI.Xaml.Style (value.TargetType) + { + BasedOn = value.BasedOn + }; + foreach (var valSetter in value.Setters) + { + style.Setters.Add(valSetter); + } + + var ancestorStyles = new List<Windows.UI.Xaml.Style> (); + + Windows.UI.Xaml.Style currStyle = style; + while (currStyle.BasedOn != null) + { + ancestorStyles.Add(currStyle.BasedOn); + currStyle = currStyle.BasedOn; + } + + foreach (var styleParent in ancestorStyles) + { + foreach (var b in styleParent.Setters) + { + var parentSetter = b as Windows.UI.Xaml.Setter; + if (parentSetter == null) + continue; + + var derviedSetter = style.Setters + .OfType<Windows.UI.Xaml.Setter> () + .FirstOrDefault (x => x.Property == parentSetter.Property); + + //Ignore any ancestor setters which a child setter has already overridden + if (derviedSetter != null) + continue; + else + style.Setters.Add (parentSetter); + } + } + return style; + } + static LineBreakMode ToLineBreakMode (TextWrapping value) { switch (value) { |