Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the height of the a WPF `<Separator />`?

I use the wpf in a list menuitems in a normal menu (not the context menu).

Using the following style, the separator is not drawn:

<Style x:Key="{x:Static MenuItem.SeparatorStyleKey}" TargetType="{x:Type Separator}">
    <Setter Property="Height" Value="2" />
</Style>

The value of Height must at least be 12, but then the distance from menuitems is too large.

What is happening here? Is it logical? Is there a solution?

like image 506
Gerard Avatar asked Oct 28 '25 20:10

Gerard


2 Answers

Simply scale the separator on the Y axis

 <Separator>
    <Separator.RenderTransform>
        <ScaleTransform ScaleY="3" />
     </Separator.RenderTransform>
 </Separator>

This will set the separator's height to 3 times the original one.

see this: How to: Scale an Element

like image 96
Omar Bousbia Avatar answered Oct 30 '25 14:10

Omar Bousbia


You can use the Margin property to size and/or space the Separator element to a degree:

<StackPanel>
    <Button Width="100" Content="Click me" />
    <Separator Margin="50,20" />
    <Button Width="100" Content="Click me too" />
</StackPanel>

In general, its length will fill the available area, while its width will remain at one pixel, or vice versa depending on its orientation. This will affect its Width:

<StackPanel>
    <Button Width="100" Content="Click me" />
    <Separator Margin="20" Width="20" />
    <Button Width="100" Content="Click me too" />
</StackPanel>

This won't affect the Height of the line in this orientation, but it will affect the total space that it takes:

<StackPanel>
    <Button Width="100" Content="Click me" />
    <Separator Margin="20" Height="50" />
    <Button Width="100" Content="Click me too" />
</StackPanel>

If you want more control over the line, then I would recommend that you use the Line Class instead.

like image 27
Sheridan Avatar answered Oct 30 '25 15:10

Sheridan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!