为资源字典分配源时出错
我一直在尝试将资源字典放入我的 Visual Studio C# Express 项目中,并且看到了很多提供建议的网站,并且尝试了其中的大多数。资源字典位于我的项目的主文件夹中,没有子目录。字典本身 (rd.xaml) 是从正在运行的 IronPython 项目导入的。目前尚不清楚是什么导致了错误,但它总是在语句 rd.Source = ....;
上失败 我不确定文件名是否指定错误,但我早上大部分时间都在谷歌搜索和测试解决方法。
ResourceDictionary rd = new ResourceDictionary();
Uri absoluteUri = new Uri("pack://application:,,,/rd.xaml", UriKind.Absolute);
rd.Source = absoluteUri; // **strong text** DIES HERE
Application.Current.Resources.MergedDictionaries.Add(rd);
I've been trying to get a resource dictionary into my visual studio c# express project, and have seen quite a few sites offering advice and have tried most of them. The resource dictionary is in the main folder of my project, no sub-directories. The dictionary itself (rd.xaml) was imported from a working IronPython project. It's unclear what is causing the error, but it always fails on the statement rd.Source = ....;
I'm not sure if the file's name is specified incorrectly, but I've been googling and testing for a workaround most of the morning.
ResourceDictionary rd = new ResourceDictionary();
Uri absoluteUri = new Uri("pack://application:,,,/rd.xaml", UriKind.Absolute);
rd.Source = absoluteUri; // **strong text** DIES HERE
Application.Current.Resources.MergedDictionaries.Add(rd);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回答了我自己的问题。事实证明,Visual Studio 抛出了一个通用错误,并且对 VS 相当不熟悉/菜鸟,没有意识到我可以在错误对话框的“详细信息”中获得几个级别的 InnerException。当我到达那里时,错误是“...找不到文件.....\bin\Debug\rd.xaml”。
我将 rd.xaml 复制到项目的 \bin\Debug 中,效果很好。叹。
肯
answered my own question. It turns out Visual Studio was throwing a generic error, and being rather unfamiliar/noob with VS, didn't realize I could get down a couple levels of InnerException in the Details of the error dialog. When I got there, the error was "... couldn't find file .....\bin\Debug\rd.xaml".
I copied rd.xaml into the project's \bin\Debug, and it works great. Sigh.
Ken