Search code examples
c#wpfxamlresourcedictionaryclass-library

ResourceDictionary in WPF class library


I have a Class Library with the following bits of code.

Below is my UserControl's Resource:

<UserControl.Resources>
    <ResourceDictionary Source="pack://application:,,,/Mine.Controls;component/Templates.xaml" />
</UserControl.Resources>

And below here is my ResourceDictionary file named Templates.xaml:

Build action: Resource

Copy to ...: Do not copy

Custom tool:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ControlTemplate x:Key="MyButton"
                     TargetType="Button">
        <Border x:Name="buttonBorderOuter"
                BorderBrush="#DBDBDB"
                BorderThickness="1"
                Background="#00ECECEC"
                CornerRadius="5" />
    </ControlTemplate>
</ResourceDictionary>

I then get the error

Exception: An error occurred while finding the resource dictionary "pack://application:,,,/Mine.Controls;component/Templates.xaml".

What am I doing wrong?


Solution

  • Try to change the build action for Templates.xaml to Page.