Accessing base class Resources in a WPF Page class
I've got a custom WPF Application
base class which has a set of resources specified in XAML in the Application.Resources
property. I've changed the build action to Page
from ApplicationDefinition
.
Now I have another project, and I changed the App class to inherit from my custom application base above. However, I can't find how to access the resources which were specified in the base class's XAML file开发者_运维技巧.
How can I load and access those resources, merging it with my derived Application
classes Resources
?
One thing you might be able to do is to use a merged dictionary. Its not exactly "inherited" but it works. I would separate out your resources into a shared xaml dictionary file, and then reference it from both your base Application, as well as your inheriting.
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictonary Source="pack://application:,,,/ASSEMBLY;component/PATHTOSHAREDDICTIONARY"/>
</ResourceDictionary.MergedDictionaries>
<!-- More Resources can go here -->
</ResourceDictionary>
</Application.Resources>
I'm not sure how this is going to play with your Application, but it might be worth a shot. Good luck!
Note that ASSEMBLY and PATHTORESOURCEDICTIONARY will need to be replaced in your pack syntax.
精彩评论