Create your resource key with ComponentResourceKey. Regular resource keys are searched only for the visual tree and application resources. But any resource key that is ComponentResourceKeyalso executed in the theme dictionary for the assembly containing this type. (This is also true for Typeobjects used as resource keys.)
In your /Generic.xaml themes of an assembly containing a control called Sandwich, you can:
<SolidColorBrush x:Key="{ComponentResourceKey local:Sandwich, Lettuce}"
Color="#00FF00" />
<ControlTemplate x:Key="{ComponentResourceKey local:Sandwich, PeanutButter}" ...>
...
</ControlTemplate>
You can reference these resources in code as follows:
var lettuce = (Brush)FindResource(
new ComponentResourceKey(typeof(Sandwich), "Lettuce"));
var penutButter = (ControlTemplate)FindResource(
new ComponentResourceKey(typeof(Sandwich), "PeanutButter"));
You can also reference these resources in XAML as follows:
<Border Background="{StaticResource ResourceKey={ComponentResourceKey local:Sandwich, Lettuce}}" />
, FindResource, XAML , FrameworkElement, FrameworkContentElement Application.
ComponentResourceKey , , . , ComponentResourceKey {ComponentResourceKey local:Sandwich,Seasonings}, Soup Sandwich . ComponentResourceKey , , , .
, URI ResourceDictionary , . Themes/Generic.xaml, , .
, Themes/Generic.xaml, ThemeInfoAttribute . AssemblyInfo.cs:
[assembly:ThemeInfoAttribute(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]