In CSS it is possible to style HTML elements based on their location in the element tree:
div#container div#menu a
I'd like to do the same in WPF, so that only links in a menu section are styled.
I was thinking about the following for Separators nested in a StatusBar:
<Style TargetType="{x:Type StatusBar}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Padding" Value="0,0,20,0" />
<Style.Resources>
<Style TargetType="{x:Type Separator}">
<Setter Property="Width" Value="20" />
<Setter Property="Background" Value="Green" />
</Style>
</Style.Resources>
</Style>
This piece of XAML is included in a resource dictionary. The StatusBar shows up with a transparent background and correct padding. However, the green separator unfortunately doesn't display. It just shows the default gray 1px wide bar.
Thanks in advance.
Stumbled upon an answer myself. The code I mentioned is correct for every case, except the Separator. The Separator element should be styled with a specific key, detailed described here: http://devlicio.us/blogs/christopher_bennage/archive/2008/06/19/styling-separators-in-wpf.aspx.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With