简体   繁体   中英

Share resources between dlls

I already read a bunch of post about resources dictionary, but none works in my case. My solution is formed only by dlls, that are consumed from Delphi (VCL) application. These dlls, has windows (WPF) forms, and so on..

Where can I put some resource dictionary, such a way that all dlls can reuse then ?

Not sure what you mean by "resources" exactly, but you can add files into a .dll by including them in your project (just create a new folder "resources", then right click and add existing item to it).

Right click and select properties on the file you just added. Under Build Action , select Embedded Resource . When you compile your project now, the file will be included within the .dll.

I'm sure you can find lots of info about accessing embedded resources; see this SO post, for instance, about reading from an embedded text file.

I get this to work, following this steps:

  1. I create a new dll project, and add new item "Resource Dictionay (WPF)" in it. In this file I declare my custom resources, like this:

     <Style TargetType="Button"> <Style.Triggers> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Opacity" Value="0.30"></Setter> </Trigger> <Trigger Property="IsEnabled" Value="True"> <Setter Property="Opacity" Value="1"></Setter> </Trigger> </Style.Triggers> <Setter Property="Background" Value="Transparent"></Setter> <Setter Property="BorderBrush" Value="Transparent"></Setter> </Style> 

  2. In my other projects, I refer to this resource this way in XAML:

     <Window.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/my.project.here;component/Assets/CommonDictionary.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> 

  3. That´s it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM