1

I need to add a vertical separator of some kind in a WPF XAML ListView. Currently my code looks like this:

<GridViewColumn Width="10" x:Name="seperator">
    <GridViewColumn.CellTemplate>
        <DataTemplate>
            <Border BorderBrush="#FF000000" BorderThickness="1,0,1,0" Margin="-6,-2,-6,-2">
                <Grid Background="Black" Margin="-1, -14, -1, -14"/>
            </Border>
        </DataTemplate>
    </GridViewColumn.CellTemplate>
</GridViewColumn>

It feels like it should be easier to either fill the background of the column or set a border on the right/left. The results I've found seem to be dynamic or for rows.

Chris Culver
  • 38
  • 1
  • 7
  • Does this answer your question? [A vertical Separator control in a Menu, Toolbar, StackPanel, etc. - Is it possible?](https://stackoverflow.com/questions/4011571/a-vertical-separator-control-in-a-menu-toolbar-stackpanel-etc-is-it-possib) – Mike Nakis Mar 08 '21 at 10:20

2 Answers2

5

This will create a vertical separator using default ToolBar style, but you can use your own style if you prefer.

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>

    <StackPanel Grid.Column="1" Orientation="Horizontal">
        <Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" />
    </StackPanel>
</Grid>
Roger Leblanc
  • 1,543
  • 1
  • 10
  • 9
0

The easiest way is to use border

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <Border Grid.Column="1" Background="Grey" Width="1" Margin="10,0" />
</Grid>
Er Suman G
  • 581
  • 5
  • 12