Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. WPF - Separator Style

WPF - Separator Style

Scheduled Pinned Locked Moved WPF
csharpwpfquestion
2 Posts 2 Posters 8 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 2537300
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • U User 2537300

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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 Articles

      Just a grain of sand on the worlds beaches.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups