I am new to WPF. I dont know how to do this.
I have this style defined -
<Style TargetType="{x:Type Button}" x:Key="StandardButton">
<Setter Property="Background" Value="{StaticResource LightBackground}"/>
<Setter Property="Foreground" Value="{StaticResource Foreground}"/>
</Style>
I have a control template -
<ControlTemplate x:Key="ExpanderTemplate" TargetType="{x:Type Expander}">
<ControlTemplate.Resources>
<Style TargetType="{x:Type Button}" /* Here I need to put above defined style */></Style>
</ControlTemplate.Resources>
</ControlTemplate>
If you want all
Buttonsin yourControlTemplateto use theStylejust remove thex:Keyfrom the style and add to theControlTemplate.ResourcesStyleswith anx:Keywill have to be declared on the control likeStyle="{StaticResource StandardButton}", to apply to all controls in the scope of theResourcesyou only have to declare theTargetTypeIf you already have a
Styledefined in your higher levelResourcesand you want to apply to all theButtonsin yourControlTemplateyou can use theBasedOnproperty.Example:
This will apply
StandardButtonStyleto all Buttons in the scope of theResourcesit was defined, in this case all theButtonsin theExpanderTemplate