Resource Dictionary as Linked File

走远了吗. 提交于 2019-12-25 03:41:43

问题


Resource dictionary

03-11-2010 10:56 AM |

I have two different projects. I linked a resource directory in using add existing item add as link.

Silverlight does not see the resource dictionary when it is a linked file and give me an out of range error.

Any work around to this or any better way to use the same file across two projects?


回答1:


I would reference the assembly that has the resource dictionary normally (don't add it in as a link), and then bring it into the application using Merged Dictionaries. You can specify a resource dictionary in an external assembly to merge into the current application or page's resource dictionaries.

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/SharedThemeAssembly;component/MyStyles.xaml"/>
            ...other ResourceDictionaries to merge in...
        </ResourceDictionary.MergedDictionaries>
     </ResourceDictionary>
</Application.Resources>

I answered a similar SO question here: Silverlight: Multiple project sharing the same style files




回答2:


If the share is between a silverlight and a WPF project, I find it easier to put the file inside the silverlight project, and link it to the WPF project, than doing it the other way around.

In other words the file is moved to the silverlight project, not the WPF project, then "linked" to the WPF project.

Also remember when the file is referenced from WPF, since it is linked, you need to change the reference URL as if it is in the root, like so:

<ResourceDictionary 
    Source="pack://application:,,,/AssemblyName;component/DictionaryName.xaml" />

Removing the folder above works, the uri below does NOT work:

<ResourceDictionary 
    Source="pack://application:,,,/AssemblyName;component/FOLDER/DictionaryName.xaml" />


来源:https://stackoverflow.com/questions/2426753/resource-dictionary-as-linked-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!