Why can't I move the resource dictionary to Silverlight?

For some reason, the following code gives me an exception.

<Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/PPCa.Common.Infrastructure;component/Skins/Default.xaml"/> <ResourceDictionary> <app:ResourceWrapper x:Key="ResourceWrapper" /> <app:NotOperatorValueConverter x:Key="NotOperatorValueConverter" /> </ResourceDictionary> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> 

Here is the exception:

 System.Windows.Markup.XamlParseException occurred Message=Failed to assign to property 'System.Windows.ResourceDictionary.Source'. [Line: 11 Position: 44] LineNumber=11 LinePosition=44 StackTrace: at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator) InnerException: 

Line 11 is as follows:

 <ResourceDictionary Source="/PPCa.Common.Infrastructure;component/Skins/Default.xaml"/> 

Did I somehow change the dictionaries incorrectly?

+4
source share
4 answers

Why is no one answering my questions? I'm blacklisted or something like that. People are used to helping me a lot more. Anyway, I discovered my problem. The exception was red herring. The problem had nothing to do with the application resource definition. The problem I had was deep inside my resource dictionaries. I was merging, referring to a dictionary inside my dictionary that no longer exists. It was hard to understand.

+9
source

Are these dictionaries in the same XAP? If so, the relative path should work. I used all relative paths for merging in dictionaries without any problems. Here is my example:

 <Application.Resources> <ResourceDictionary x:Name="appDictionary"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary x:Name="ControlStylesDictionary" Source="Resources/Styles/ControlStyles.xaml" /> <ResourceDictionary x:Name="MenuStylesDictionary" Source="Resources/Styles/MenuStyles.xaml" /> </ResourceDictionary> </Application.Resources> 

This is the only difference that I see in your XAML.

+4
source

If the dictionary is in another XAP, you need to download XAP and load the dictionary there .

+3
source

I ran into the same problem, with the same general error message and found a solution. This seems to be an IMHO bug.

I am creating an application for .Net, SL5, WP7.1. To do this, I put the code in the .Net application and add the source links for other projects. It works great.

My main application projects are called MyApp.Net, MyApp.SL and MyApp.WP. However, I am making the default namespace and the project for these projects is simply MyApp. Again, it works just as it should.

I place my resources in MyApp.Resources.Net, MyApp.Resources.SL and MyApp.Resources.WP projects. There is a little glitch using VS source links, because Expression Blend wants direct access to physical files and gets confused when (for example) the MyApp.Resources.WP project contains the source link in the MyStyles.xaml file in MyApp.Resources.Net Projects. Therefore, all my resource projects actually contain physical files. This works great, I just need to sync the files manually. There are no problems at the moment.

However, for my resource projects, I am changing the namespace and output files to MyApp.Resources. It also simplifies my application code, regardless of the platform for which it is created, the namespace is the same.

Yes, I know that this is a bit complicated, but it allows me to create 3 platforms (technically 5 if you enable Blendability and UnitTesting) with the same code base.

To continue if I create a ResourceDictionary as such

 <ResourceDictionary Source="/MyApp.Resources;component/Styles/TextStyles.xaml"/> 

I get the message "Failed to set the property" System.Windows.ResourceDictionary.Source ", etc.

In short, I found that if the assembly name contains '.' this error appears. For example, if I change the project names to just β€œResources”, it works fine. Or, if I leave my projects with default names for the assembly "MyApp.Resources.WP", it also works fine.

This has nothing to do with changing the name of the output dll files of my resource, I change them all day and it works fine, but if they contain '.' I get the above error. For example, I can change the output name to "MyAppResourceThatWorks" (leaving the project name as MyApp.Resources.WP and loading it into App.xaml using

 <ResourceDictionary Source="/MyAppResourceThatWorks;component/Styles/TextStyles.xaml"/> 

It works great. Change the output name to "MyAppResourcesThatDoNot.Work" and load it with

 <ResourceDictionary Source="/MyAppResourceThatDoNot.Work;component/Styles/TextStyles.xaml"/> 

Fails.

Yes, I tried to change the properties of the assembly, etc. etc. This is a download problem with Pack Uri's.

+1
source

Source: https://habr.com/ru/post/1341886/


All Articles