A bit late for an answer, but it can benefit others.
The resource you are trying to access at the topic level must be identified by ComponentResourceKey to access it from anywhere in the assembly:
<Style TargetType="{x:Type TreeViewItem}" x:Key="{ComponentResourceKey {x:Type local:MyTVIStyleSelector}, tviBaseStyle}"> </Style>
then in your XAML you refer to it like this:
<Style TargetType="{x:Type TreeViewItem}" x:Key="{ComponentResourceKey {x:Type local:MyTVIStyleSelector}, tviStyle_1}" BasedOn={StaticResource {ComponentResourceKey {x:Type local:MyTVIStyleSelector}, tviBaseStyle}}> </Style>
and in your code:
ComponentResourceKey key = new ComponentResourceKey(typeof(MyTVIStyleSelector), "tviStyle_1"); Style style = (Style)Application.Current.TryFindResource(key);
There is also a verbose form of XAML syntax that looks like this (but it's the same thing):
<Style TargetType="{x:Type TreeViewItem}" x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:MyTVIStyleSelector}, ResourceId=tviBaseStyle}"> </Style>
Please note that even if TypeInTargetAssembly must be installed, it does not restrict access to this resource to other types in the assembly.
source share