}
}
- static ResourceDictionary _instance;
+ static Dictionary<Type, ResourceDictionary> _instances;
static ResourceDictionary GetInstance(Type type)
{
- return _instance ?? (_instance = ((ResourceDictionary)Activator.CreateInstance (type)));
+ _instances = _instances ?? new Dictionary<Type, ResourceDictionary>();
+ ResourceDictionary rd;
+ if (!_instances.TryGetValue(type, out rd))
+ {
+ rd = ((ResourceDictionary)Activator.CreateInstance(type));
+ _instances [type] = rd;
+ }
+ return rd;
}
ResourceDictionary _mergedInstance;
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Xamarin.Forms.Xaml.UnitTests.SharedResourceDictionary2">
+ <Style x:Key="sharedStyle2" TargetType="Label">
+ <Setter Property="TextColor" Value="Purple"/>
+ </Style>
+</ResourceDictionary>
--- /dev/null
+using System;
+using System.Collections.Generic;
+
+using Xamarin.Forms;
+
+namespace Xamarin.Forms.Xaml.UnitTests
+{
+ public partial class SharedResourceDictionary2 : ResourceDictionary
+ {
+ public SharedResourceDictionary2 ()
+ {
+ InitializeComponent ();
+ }
+ }
+}
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Xamarin.Forms.Xaml.UnitTests"
x:Class="Xamarin.Forms.Xaml.UnitTests.TestSharedResourceDictionary">
- <ContentPage.Resources>
- <ResourceDictionary MergedWith="local:SharedResourceDictionary">
- </ResourceDictionary>
- </ContentPage.Resources>
- <Label x:Name="label" Style="{StaticResource sharedfoo}"/>
+ <StackLayout>
+ <ContentView>
+ <ContentView.Resources>
+ <ResourceDictionary MergedWith="local:SharedResourceDictionary"/>
+ </ContentView.Resources>
+ <Label x:Name="label" Style="{StaticResource sharedfoo}"/>
+ </ContentView>
+ <ContentView>
+ <ContentView.Resources>
+ <ResourceDictionary MergedWith="local:SharedResourceDictionary2"/>
+ </ContentView.Resources>
+ <Label x:Name="label2" Style="{StaticResource sharedStyle2}"/>
+ </ContentView>
+ </StackLayout>
+
</ContentPage>
\ No newline at end of file
var layout = new TestSharedResourceDictionary (useCompiledXaml);
Assert.AreEqual (Color.Pink, layout.label.TextColor);
}
+
+ [TestCase (false)]
+ [TestCase (true)]
+ public void NoConflictsBetweenSharedRDs (bool useCompiledXaml)
+ {
+ var layout = new TestSharedResourceDictionary (useCompiledXaml);
+ Assert.AreEqual (Color.Pink, layout.label.TextColor);
+ Assert.AreEqual (Color.Purple, layout.label2.TextColor);
+ }
}
}
}
\ No newline at end of file
<Compile Include="TestSharedResourceDictionary.xaml.cs">
<DependentUpon>TestSharedResourceDictionary.xaml</DependentUpon>
</Compile>
+ <Compile Include="SharedResourceDictionary2.xaml.cs">
+ <DependentUpon>SharedResourceDictionary2.xaml</DependentUpon>
+ </Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\.nuspec\Xamarin.Forms.Debug.targets" />
<EmbeddedResource Include="TestSharedResourceDictionary.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
+ <EmbeddedResource Include="SharedResourceDictionary2.xaml">
+ <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+ </EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />