Reputation: 1153
Maybe I'm misunderstanding how this all works and you can't really stuff plain old XAML files into a DLL as data which can be grabbed out later - but I thought this was possible.
I have tried over and over and over again for like five hours to get this to work so I'm finally asking Stack Overflow.
I have a XAML file in a WPF User Control Library project. In a perfect world, I should be able to have this XAML file embedded in some way into the DLL for reference in another project. I don't want to link to the original project folder or anything like that if possible just to keep everything nice and simple and in one place.
So here are the questions that are tripping me up:
If you compile a DLL with a file in the project that's compile mode is set to "resource" - does that file actually get stuffed into the DLL? If it doesn't - is there a way to do that?
Say my resource file is pathed as such in the Class Library project:
"MyClassLibrarySolutionRoot/StyleXAMLs/Styles.xaml"
What do I put for the URI path in the application file:
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="What on earth am I supposed to put here?"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Thanks in advance! FYI this particular problem has made me a bit batty regarding trying to learn XAML because failure to make it work really breaks the workflow I like to have by basically throwing absolutely everything except the base application's code into class libraries. So, maybe you can restore my faith in XAML by assuring me I can still easily use and reference DLLs?
PS... I have tried this exact format for the URI over and over and it doesn't work: pack://application:,,,/externalDllName;component/path/dictionary.xaml
Is "component" supposed to be the word "component" or is it supposed to be something else like "ResourceDictionary"? Is that "path" supposed to be the names of the folders in the original DLL project or something else?
Here, I decided to include a picture because I have no idea what I'm doing wrong:
Upvotes: 2
Views: 3024
Reputation: 1153
Well, as foolish as it may sound I wasn't looking carefully enough and finally discovered that it was throwing a parse error on a URI on a completely different part of the class library.
What caused me to be misled was trying to add a the resourcedictionary to App.xaml. The IDE kept giving me the error "Assembly is not referenced by this project" leading me to believe the parse error was a result of the URI with the underlying error and I didn't even stop to consider that it was a URI in C# code in the class library that was throwing the parse error.
Sorry to have wasted the time of people here - but the small lesson to be learned is the following:
Visual Studio will occasionally give erroneous errors when trying to reference an external assembly in XAML code which may lead you to look at the wrong part for your parse exception.
Upvotes: 1