Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to do something like this:

XML
<Style TargetType="Control">
  <Setter Property="VerticalAlignment" Value="Center"></Setter>
</Style>


Is this possible? It doesn't work this way...
I know I could write for every control something like the following:

XML
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource M<ControlBaseStyle}"/>


But I have 10 different controls and I don't really want to do this.

Any ideas?

Thank you!
Markus
Posted

1 solution

You can't do this, but you can create one style and then use it for other controls.

If you have the following Style
XML
<Style x:Key="ControlBaseStyle" TargetType="{x:Type Control}">
    <Setter Property="Margin" Value="50" />
</Style>


You can target all Buttons for instance

XML
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource ControlBaseStyle}"/>


You still need to add the style for each control type, but you can make it so the actual style is only there once.
 
Share this answer
 
Comments
NeonMika 22-Aug-12 9:26am    
Okay, so I have to write down the "tree". Thanks for your answer, 5*.
Christian Graus 22-Aug-12 9:27am    
glad to help :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900