相关疑难解决方法(0)

动态加载资源字典文件到wpf应用程序会出错

我正在尝试使用该语句动态添加xaml资源文件,

Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri("resources/leaf_styles.xaml", UriKind.Relative) });
Run Code Online (Sandbox Code Playgroud)

这是抛出异常,无法找到资源'resources/leaf_styles.xaml'.

我将leaf_styles.xaml文件添加到资源文件夹下的项目中,BuildAction设置为"Content",CopyAlways设置为True.我仍然得到这个错误.有人可以帮我指出什么错?

附加信息 -

  • 我不想将xaml文件嵌入为资源
  • 当前项目是.net 3.5类库项目
  • 上面的mergedictionary语句是在属于同一个项目的类中编写的
  • 一旦我发现这不起作用(用于测试),我还手动添加了[assembly:AssemblyAssociatedContentFile("resources/leaf_styles.xaml")]

更新

如果我把它作为绝对位置,它正常工作.

Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri(@"D:\foo\trunk\bin\resources\leaf_styles.xaml", UriKind.Absolute) });
Run Code Online (Sandbox Code Playgroud)

.net c# wpf xaml resourcedictionary

10
推荐指数
2
解决办法
3万
查看次数

枚举嵌入式资源目录中的文件

在WPF中,是否有一种方法可以枚举特定嵌入式资源目录中的所有文件?也就是说,所有项目的目录都具有设置为"资源"的"构建动作".

wpf resources enumerate

7
推荐指数
1
解决办法
4332
查看次数

标签 统计

wpf ×2

.net ×1

c# ×1

enumerate ×1

resourcedictionary ×1

resources ×1

xaml ×1