22 Şubat 2018 Perşembe

Solved: "The resource "{x:Type common:MyCustomControl}" could not be resolved."

I have a project where multiple WPF applications share a "common" library.  This library includes some common WPF resources, utility methods, etc.

I ran into a problem when I decided to move a custom control from the apps into the common library. I moved the custom control definition (MyCustomControl.cs) and the Theme/Generic.xaml, which contains the default style / template for my control.

In one of the applications, I was trying to further customize the default style by creating a style based on the default style:

<Style TargetType="common:MyCustomControl" BasedOn="{StaticResource {x:Type common:MyCustomControl}}">

   ...

</Style>
The StaticResource had an error that said "The resource "{x:Type common:MyCustomControl}" could not be resolved."

Solution:

It turned out I forgot to add the ThemeInfo assembly attribute, which defines where the themes are stored in the assembly.  When I added the following in the AssemblyInfo.cs in my common library, the problem was solved:

[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]


Hiç yorum yok:

Yorum Gönder