Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Resources of from another project in WPF?

Tags:

c#

wpf

I have a solution under which so many WPF applications and class library projects are there. I want to use icon in another project which is under Resources folder in other WPF application. how can I achieve this ? I do not want to copy same images over and over in all different projects.

like image 791
Dirty Developer Avatar asked Jul 30 '15 05:07

Dirty Developer


People also ask

What is static resource in WPF?

Static Resource - Static resources are the resources which you cannot manipulate at runtime. The static resources are evaluated only once by the element which refers them during the loading of XAML.

What are the resources in WPF?

WPF supports different types of resources. These resources are primarily two types of resources: XAML resources and resource data files. Examples of XAML resources include brushes and styles. Resource data files are non-executable data files that an application needs.

What is application resource file?

In Android, a resource is a localized text string, bitmap, layout, or other small piece of noncode information that your app needs. At build time, all resources get compiled into your application. The resources locates inside res directory of your app.


2 Answers

Use pack URI syntax to refer resources. Somethning like this:

<Image Source="pack://application:,,,/Another.Assembly.Name;component/PathToResourceInAnotherProject/YourImage.png"/>
like image 123
Dennis Avatar answered Oct 06 '22 21:10

Dennis


Yes,Microsoft makes that possible for you, as long as Project ABC has a reference to Project XYZ.

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/Project XYZ;component/YourSubFolder/YourResourceFile.xaml" />
</ResourceDictionary.MergedDictionaries>

Then you can just use the Resources defined in YourResourceFile.xaml.

like image 31
DeshDeep Singh Avatar answered Oct 06 '22 22:10

DeshDeep Singh