#StackBounty: #c# #wpf #.net-5 #class-library WPF Resources in class library in .NET 5

Bounty: 100

In .NET Framework, when I create a WPF class library, I have my App.xaml (set as Application definition) referencing my resource dictionaries like that:

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="ResourceDictionary1.xaml" />
                <ResourceDictionary Source="ResourceDictionary2.xaml" />
                <ResourceDictionary Source="ResourceDictionary3.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

However, with .NET 5, I get this compilation error:

Library project file cannot specify ApplicationDefinition element.

I understand what this message means, but I don’t know how to define my resources globally in a class library. Isn’t there any way to do this without referencing the dictionaries in each and every XAML file in the project?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.