开发者

Accessing base class Resources in a WPF Page class

开发者 https://www.devze.com 2023-03-12 09:52 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号