Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load WPF styles or other Static Resources from an external file or assembly

I have a few WPF applications and I want all my styles to be in a shared assembly instead of declaring them in each application separately.

I am looking for a way so I don't have to change all my Style="{StaticResource BlahBlah}" in the existing applications; I just want to add the reference to this style assembly, and delete it from the current application, so it's taken from the assembly.

Is there any way?

like image 983
Shimmy Weitzhandler Avatar asked Apr 01 '09 18:04

Shimmy Weitzhandler


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 WPF resources?

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 a XAML resource dictionary?

A resource dictionary is a repository for XAML resources, such as styles, that your app uses. You define the resources in XAML and can then retrieve them in XAML using the {StaticResource} markup extension and {ThemeResource} markup extension s. You can also access resources with code, but that is less common.


1 Answers

Referencing an external ResourceDictionary (XAML File):

<Application.Resources>     <ResourceDictionary Source="MyResources.xaml" /> </Application.Resources> 

Referencing an external ResourceDictionary (DLL):

<Application.Resources>     <ResourceDictionary Source="/MyExternalAssembly;component/MyResources.xaml" /> </Application.Resources> 
like image 167
Shimmy Weitzhandler Avatar answered Sep 17 '22 13:09

Shimmy Weitzhandler