我的项目中有一个文件夹,Template,充满了(编译的) XAML ResourceDictionaries。
在UserControl中,我希望将所有模板加载到ResourceDictionary中。我将使用如下代码:
public MyView()
{
InitializeComponent();
foreach (var resourceUri in new GetResourceUrisFromTemplatesFolder())
Resources.MergedDictionaries.Add(
new ResourceDictionary
{ Source = new Uri(resourceUri, UriKind.Relative) });
}我需要编写的是GetResourceUrisFromTemplatesFolder方法。我需要它来发现那个文件夹中的所有资源。
URI可以采用类似于/MyAssembly;component/MyNS/Templates/Template12345.xaml或../../Templates/Template12345.xaml的形式。
这个是可能的吗?
是否必须手动转换程序集的编译资源(MyAssembly.g.resources)中的名称?
发布于 2011-06-30 14:39:52
,我必须手动转换程序集的编译资源(MyAssembly.g.resources)中的名称吗?
可能是这样的,我自己也会这么做,但是,关于如何做has been answered的问题,应该不是什么大问题。确保字典的编译操作匹配,并且您可能希望在名称前面加上一个包uri。
发布于 2013-06-12 17:14:10
顺便说一句,还可以手动加载ResourceDictionary:
ResourceDictionary dict = new ResourceDictionary();
System.Windows.Application.LoadComponent(dict,
new System.Uri("/SomeAssembly;component/SomeResourceDictionary.xaml",
System.UriKind.Relative));之后,可以在它拥有的Keys属性上使用foreach与该dict对象进行交谈。
在http://msdn.microsoft.com/en-us/library/ms596995(v=vs.95).aspx说
加载的XAML文件可以是应用程序定义文件(例如,App.xaml)>,也可以是页面文件(例如,MainPage.xaml)。XAML文件可以位于以下位置之一:
应用程序包中包含了
https://stackoverflow.com/questions/6536124
复制相似问题