Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should you use ComponentResourceKey instead of a string as a resource key?

Tags:

wpf

The help topic page on ComponentResourceKey doesn't give great guidance on when you would want to move from a string-based key to a ComponentResourceKey for putting and/or retrieving resources from a ResourceDictionary. Does anybody have any insight on when you would want to use a ComponentResourceKey over a string?

like image 738
Keith Hill Avatar asked Aug 02 '12 19:08

Keith Hill


1 Answers

From what I understand about ComponentResourceKeys is that they establish global uniqueness by defining themselves with respect to a type, and are required for referencing resources defined in generic or theme dictionaries.

Resources you store in a theme dictionary (eg generic.xaml) are only accessible via ComponentResourceKey and not a normal x:Key UNLESS you explicitly reference the generic.xaml into the MergedDictionaries collection of a Resources collection (eg at the App or Window or element level) but you should not do this as this is not the intent of generic.xaml

like image 93
blue18hutthutt Avatar answered Oct 21 '22 08:10

blue18hutthutt