我正在尝试使用以下语句动态添加一个XAML资源文件:
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri("resources/leaf_styles.xaml", UriKind.Relative) });
这里抛出了一个异常,无法找到资源'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) });