如何访问另一个项目中一个项目的资源字典? [英] how to access the resource dictionary of one project in another project ?
本文介绍了如何访问另一个项目中一个项目的资源字典?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何访问另一个项目中一个项目的资源字典?当我从资源字典访问模板时,我收到错误。告诉我如何访问资源字典的模板。举个例子?
解决方案
你可以访问它就像(只要Project 2引用了Project 1)。
< < span class =code-leadattribute> ResourceDictionary.MergedDictionaries >
< ResourceDictionary 来源 = /< YourAssemblyName> ;; component /< YourReferencedFileHere.xaml> / >
< / ResourceDictiona ry.MergedDictionaries >
类似的问题已回答其中 [ ^ ]
在此处阅读更多内容: MSDN:合并资源词典 [ ^ ]
您需要知道ResourceDictionary的Uri。您可以轻松使用以下代码来检索它:private ResourceDictionary GetResourceDictionary( string 汇编,字符串 packUri)
{
汇编 assembly = Assembly.LoadFrom( assembly );
return dictionary = Application.LoadComponent( new Uri(packUri,UriKind.Relative))< span class =code-keyword> as ResourceDictionary;
}然后,您可以这样调用它:
ResourceDictionary dictionary = GetResourceDictionary( < span class =code-string> MyAssembly.dll, @ / MyAssembly; component / Resources /MyResource.xaml跨度>;
how to access the resource dictionary of one project in another project ? i am getting error when i am accessing the template from the resource dictionary .Tell me how to access the template of resource dictionary .give some example ?
解决方案
You can access it like (as long as Project 2 has a reference to Project 1.):
<ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/<YourAssemblyName>;component/<YourReferencedFileHere.xaml>" /> </ResourceDictionary.MergedDictionaries>
Similar question asked and answered here[^]
Read more here: MSDN: Merged Resource Dictionaries[^]
You need to know the Uri of the ResourceDictionary. You can easily use the following code to retrieve it:private ResourceDictionary GetResourceDictionary(string assembly, string packUri) { Assembly assembly = Assembly.LoadFrom(assembly); return dictionary = Application.LoadComponent(new Uri(packUri, UriKind.Relative)) as ResourceDictionary; }Then, you can call it like this:
ResourceDictionary dictionary = GetResourceDictionary("MyAssembly.dll", @"/MyAssembly;component/Resources/MyResource.xaml";
这篇关于如何访问另一个项目中一个项目的资源字典?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文