How to add a vertical Separator? How to add a vertical Separator? wpf wpf

How to add a vertical Separator?


This should do exactly what the author wanted:

<StackPanel Orientation="Horizontal">    <Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" />            </StackPanel>

if you want a horizontal separator, change the Orientation of the StackPanel to Vertical.


This is not exactly what author asked, but still, it is very simple and works exactly as expected.

Rectangle does the job:

<StackPanel Grid.Column="2" Orientation="Horizontal">    <Button >Next</Button>    <Button >Prev</Button>    <Rectangle VerticalAlignment="Stretch" Width="1" Margin="2" Stroke="Black" />    <Button>Filter all</Button></StackPanel>


In the past I've used the style found here

<Style x:Key="VerticalSeparatorStyle"        TargetType="{x:Type Separator}"       BasedOn="{StaticResource {x:Type Separator}}">    <Setter Property="Margin" Value="6,0,6,0"/>    <Setter Property="LayoutTransform">        <Setter.Value>            <TransformGroup>                <TransformGroup.Children>                    <TransformCollection>                        <RotateTransform Angle="90"/>                    </TransformCollection>                </TransformGroup.Children>            </TransformGroup>        </Setter.Value>    </Setter></Style><Separator Style="{DynamicResource VerticalSeparatorStyle}" />

You need to set the transformation in LayoutTransform instead of RenderTransform so the transformation occurs during the Layout pass, not during the Render pass. The Layout pass occurs when WPF is trying to layout controls and figure out how much space each control takes up, while the Render pass occurs after the layout pass when WPF is trying to render controls.

You can read more about the difference between LayoutTransform and RenderTransform here or here