I have recently upgraded to VS 2012, I had to as I needed to start using the .net 4.5 but that is besides the point. My problem is the following:
I have a Resource
I also have this problem time to time in VS2010. Sometimes the problem will solve if I make a "Clean Solution" and a "Rebuild Solution". If that do not work I usually restart VS2010.
I have also renamed the Style x:Key to something else and the problem was gone. But I dont find this solution to be perfect...
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- Load Infrastructure's Resource Dictionaries -->
<ResourceDictionary Source="/MyProject.Modules.Infrastructure;component/ResourceDictionaries/ResourceLibrary.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- Workaround for ResourceDictionary loading bug/optimization -->
<Style TargetType="{x:Type Rectangle}" />
</ResourceDictionary>
Reference to this question regarding the Workaround in my code sample: Trouble referencing a Resource Dictionary that contains a Merged Dictionary
I had placed some Style in Window.Resources a this caused my problem
After deleting all styles from MainWindow problem disappeared.
Found second problem:
Problem was Platform Target set to x64.
After changing it to AnyCPU the resources in design works..
Also you can check for styles with the same x:key
in AppStyles.xaml. It caused me a similar error.
WPF is unable to resolve the resource dictionary that you are trying to merge. When you create a merged dictionary, WPF follows a set of rules to attempt to resolve the URI. In your case, the URI is ambiguous, so WPF is unable to reliably resolve it.
Change the Source
URI in the App.xaml
to an absolute pack URI. For example, if you project is called MyProject
(i.e.: "MyProject" is the short assembly name), then you should change the Source
in App.xaml
to:
<ResourceDictionary
Source="/MyProject;component/AppStyles.xaml"/>
This assumes AppStyles.xaml
is in the root of MyProject
. You can optionally specify the authority, assembly version and public key information of the signed assembly. However, you should be safe with the short assembly name (MyProject, in the above example).
See this page on MSDN for further details on Pack URIs in WPF: http://msdn.microsoft.com/en-us/library/aa970069(v=vs.110).aspx
you can add the resource dictionary to your project then change its build action to resource and then try to add its uri in the code as follows:
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
or simply let the vs2012 process it by using the properties tab...
you can create a common or infrastructure project from which other projects will reference. Add your resouce resources. Then create a pack URI. then reference in your usercontrol or window resources within a resource dictionary
<...Resources>
<ResourceDictionary>
<!-- Resource Dictionaries -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="pack://application:,,,/Common;component/Dictionaries/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
In the usercontrol or use Window.Resources in the case of a window. This works for me.