How can I access resources from external assembly?

AxD 666 Reputation points
2021-01-10T15:57:42.65+00:00

I don't seem to be able to access remote resources from an external assembly.

The following line in MainWindow.xaml isn't working, no background color is getting displayed:

 <StackPanel Grid.Row="0" Background="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type res:DummyForSharingResources}, ResourceId=TestBg}}"></StackPanel>  

I published a corresponding repository to GitHub containing my Visual Studio 2019 solution. It contains all the details.

What I did so far

  • "Themes/generic.xaml" file created in supplemental assembly (StylesAndResources), filled with resources.
  • ThemeInfoAttribute updated in application assembly to reference ResourceDictionaryLocation.ExternalAssembly.
  • Dummy class created in StylesAndResources in order to be able to have a ComponentResourceKey be generated.

What am I doing wrong?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,783 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
814 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. DaisyTian-1203 11,626 Reputation points
    2021-01-11T04:48:00.853+00:00

    Please add AssemblyInfo.cs to your project StylesAndResources:

    using System.Windows;  
      
    [assembly: ThemeInfo(  
        ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located  
                                         //(used if a resource is not found in the page,  
                                         // or application resource dictionaries)  
        ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located  
                                                  //(used if a resource is not found in the page,  
                                                  // app, or any theme specific resource dictionaries)  
    )]  
    

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.