WPF - Separator Style
-
Hi all, i try to create a style for a menu/menuitems (changing background, fonts and so forth...). Everything works well except the background of the separators. Has anyone an idea where to specify that the background is not the windows default gray but the brush i define? thanks Rainer
-
Hi all, i try to create a style for a menu/menuitems (changing background, fonts and so forth...). Everything works well except the background of the separators. Has anyone an idea where to specify that the background is not the windows default gray but the brush i define? thanks Rainer
Take a look at the separator control template. I left the default control tempate in place without modifying it. You'll notice that although the Separartor has various public properties exposed, the template does not consume them. This is why your attempts to change it didn't work. So you can take this simple XAML and play around witht control template to get the look you desire.
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Window1"
x:Name="Window"
Title="Window1"
Width="640" Height="480">
<Window.Resources>
<Style x:Key="SeparatorStyle1" TargetType="{x:Type Separator}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Separator}">
<Grid Margin="0,6,0,4" SnapsToDevicePixels="true">
<Rectangle Margin="30,0,1,1" Height="1" Fill="#E0E0E0"/>
<Rectangle Margin="30,1,1,0" Height="1" Fill="White"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources><Grid x:Name="LayoutRoot"> <Menu HorizontalAlignment="Left" VerticalAlignment="Top" Width="Auto" Height="Auto"> <MenuItem Header="File"> <MenuItem Header="New"/> <Separator Style="{StaticResource SeparatorStyle1}"/> <MenuItem Header="Exit"/> </MenuItem> </Menu> </Grid>
</Window>
Cheers, Karl
» CodeProject 2008 MVP My Blog | Mole's Home Page | How To Create Screen Capture Videos For Your ArticlesJust a grain of sand on the worlds beaches.