I have an external style resource in a resource dictionary I'm referencing with x:Key. It has an x:TargetType specifying a target (TextBlock). Is it possible to apply this to a control containing a TextBlock and have all TextBlock elements within that control have the style applied?
Thanks, Robert
To expand a bit on other comments. When you use the syntax as Brandon showed:
The BasedOn="" is basically a kind of "inheritance" of style. This style will have as its base set of setters the ones from the style it is based on. This gives you the ability to augment the style with the options that apply only in this case or, as your case requires, to redefine the scope of the style.
You have the style in your dictionary file as a keyed style, only able to be applied explicitly. By "re-defining" your style as Brandon showed you now can re-define the scope by leaving out the key, thus making it apply to all elements of the target type in the scope of that style. So if all your TextBlocks were in a Grid you could have something like this:
No, but you can automatically apply a style to all elements of a certain type, like this:
I think this is what you are looking for:
Your custom user control "test":
Your Styles document "Res/Styles.xaml"
Your main window or parent:
The textblock in the custom control "test" now displays with a blue foreground.
The easiest way to do that would be to define a Style within the Control that is based on your external style resource, but don't specify an x:Key, just the TargetType.
Without a key, it'll apply itself to all TextBlocks within the control.