Ok, I´ll just do something you don’t want me to, says Mr Label.
Styles are one of the main reasons in, my opinion, to why WPF is a preferable choice of GUI base but sometimes, well I most definitely hate it 🙂
Look at this here XAML for my default styles:
<Style TargetType="{x:Type TextBlock}"> <Setter Property="FontSize" Value="12"/> <Setter Property="FontFamily" Value="Myriad Pro" /> </Style> <Style TargetType="{x:Type Label}"> <Setter Property="FontFamily" Value="Myriad Pro"/> <Setter Property="FontSize" Value="12"/> <Setter Property="Foreground" Value="#555555"/> </Style> <Style x:Key="LabelHeader" TargetType="{x:Type Label}"> <Setter Property="FontFamily" Value="Myriad Pro"/> <Setter Property="FontSize" Value="16"/> <Setter Property="Foreground" Value="#333333"/> </Style>
Ok, this looks fine, should produce a larger header and a smaller text for the following:
<StackPanel Orientation="Vertical"> <Label Style="{StaticResource LabelHeader}">Recent projects</Label> <Label>Please choose your project below.</Label> </StackPanel>
But guess what? They´re the exact same.
Well, as you might´ve noticed the Label takes an Object as Content property, content which is implicitly placed inside the <Label>HERE</Label> element tags.
Ok, so where does this leave me?
Text isn’t an object, thus it can’t be rendered. But WPF neatly solves this by, of course, putting a TextBox as content when we´ve got text. Thus, making our LabelHeader
style useless.
If we´ve got the same set of text properties on the label (which we want to style) the implicit style for a TextBlock shouldn’t override these values, or am I just being whiny?
For reference:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/947915ae-9b8a-4411-986d-05fb64747b94