Click here to Skip to main content
Sign Up to vote bad
good
See more: C#WPFBeginnerStyle
I would like to do something like this:
 
<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:
 
<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 22 Aug '12 - 3:18


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
<Style x:Key="ControlBaseStyle" TargetType="{x:Type Control}">
    <Setter Property="Margin" Value="50" />
</Style>
 
You can target all Buttons for instance
 
<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.
  Permalink  
Comments
NeonMika - 22 Aug '12 - 9:26
Okay, so I have to write down the "tree". Thanks for your answer, 5*.
Christian Graus - 22 Aug '12 - 9:27
glad to help :-)

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 464
1 Mahesh Bailwal 373
2 Maciej Los 255
3 Rohan Leuva 175
4 CPallini 175
0 Sergey Alexandrovich Kryukov 9,402
1 OriginalGriff 7,204
2 CPallini 3,933
3 Rohan Leuva 3,211
4 Maciej Los 2,743


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 22 Aug 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid