diff options
author | Stephane Delcroix <stephane@delcroix.org> | 2016-04-18 18:31:48 +0200 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2016-04-18 17:31:48 +0100 |
commit | 9c005f30227eaf0d3aa7d253a7c3a9ea427c91c2 (patch) | |
tree | 6e261e80af1bfa70feeecb07ac0762c8fdee2382 | |
parent | 4d279db34812891975aa0e8d73e3d5dd970a692c (diff) | |
download | xamarin-forms-9c005f30227eaf0d3aa7d253a7c3a9ea427c91c2.tar.gz xamarin-forms-9c005f30227eaf0d3aa7d253a7c3a9ea427c91c2.tar.bz2 xamarin-forms-9c005f30227eaf0d3aa7d253a7c3a9ea427c91c2.zip |
[C] Allow implicit styles and DynamicResources in shared RD (#104)
3 files changed, 20 insertions, 8 deletions
diff --git a/Xamarin.Forms.Core/ResourceDictionary.cs b/Xamarin.Forms.Core/ResourceDictionary.cs index 7460a909..bff6127b 100644 --- a/Xamarin.Forms.Core/ResourceDictionary.cs +++ b/Xamarin.Forms.Core/ResourceDictionary.cs @@ -23,6 +23,7 @@ namespace Xamarin.Forms return; _mergedInstance = _mergedWith.GetTypeInfo().BaseType.GetTypeInfo().DeclaredMethods.First(mi => mi.Name == "GetInstance").Invoke(null, new object[] {_mergedWith}) as ResourceDictionary; + OnValuesChanged (_mergedInstance.ToArray()); } } @@ -64,7 +65,7 @@ namespace Xamarin.Forms public int Count { - get { return _innerDictionary.Count; } + get { return _innerDictionary.Count + (_mergedInstance != null ? _mergedInstance.Count: 0); } } bool ICollection<KeyValuePair<string, object>>.IsReadOnly @@ -116,12 +117,15 @@ namespace Xamarin.Forms IEnumerator IEnumerable.GetEnumerator() { - return ((IEnumerable)_innerDictionary).GetEnumerator(); + return GetEnumerator(); } public IEnumerator<KeyValuePair<string, object>> GetEnumerator() { - return _innerDictionary.GetEnumerator(); + var rd = (IEnumerable<KeyValuePair<string,object>>)_innerDictionary; + if (_mergedInstance != null) + rd = rd.Concat(_mergedInstance._innerDictionary); + return rd.GetEnumerator(); } public bool TryGetValue(string key, out object value) diff --git a/Xamarin.Forms.Xaml.UnitTests/TestSharedResourceDictionary.xaml b/Xamarin.Forms.Xaml.UnitTests/TestSharedResourceDictionary.xaml index c87982f8..62c1abd2 100644 --- a/Xamarin.Forms.Xaml.UnitTests/TestSharedResourceDictionary.xaml +++ b/Xamarin.Forms.Xaml.UnitTests/TestSharedResourceDictionary.xaml @@ -4,12 +4,13 @@ xmlns:local="clr-namespace:Xamarin.Forms.Xaml.UnitTests" x:Class="Xamarin.Forms.Xaml.UnitTests.TestSharedResourceDictionary"> <StackLayout> - <ContentView> - <ContentView.Resources> + <StackLayout> + <StackLayout.Resources> <ResourceDictionary MergedWith="local:SharedResourceDictionary"/> - </ContentView.Resources> + </StackLayout.Resources> <Label x:Name="label" Style="{StaticResource sharedfoo}"/> - </ContentView> + <Label x:Name="implicitLabel" /> + </StackLayout> <ContentView> <ContentView.Resources> <ResourceDictionary MergedWith="local:SharedResourceDictionary2"/> @@ -17,5 +18,4 @@ <Label x:Name="label2" Style="{StaticResource sharedStyle2}"/> </ContentView> </StackLayout> - </ContentPage>
\ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/TestSharedResourceDictionary.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/TestSharedResourceDictionary.xaml.cs index e12e83b7..a272decc 100644 --- a/Xamarin.Forms.Xaml.UnitTests/TestSharedResourceDictionary.xaml.cs +++ b/Xamarin.Forms.Xaml.UnitTests/TestSharedResourceDictionary.xaml.cs @@ -35,6 +35,14 @@ namespace Xamarin.Forms.Xaml.UnitTests Assert.AreEqual (Color.Pink, layout.label.TextColor); Assert.AreEqual (Color.Purple, layout.label2.TextColor); } + + [TestCase (false)] + [TestCase (true)] + public void ImplicitStyleCanBeSharedFromSharedRD (bool useCompiledXaml) + { + var layout = new TestSharedResourceDictionary(useCompiledXaml); + Assert.AreEqual(Color.Red, layout.implicitLabel.TextColor); + } } } }
\ No newline at end of file |