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);
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
精彩评论