我在普通菜单(不是上下文菜单)的列表菜单项中使用 wpf。
使用以下样式,不绘制分隔符:
<Style x:Key="{x:Static MenuItem.SeparatorStyleKey}" TargetType="{x:Type Separator}">
<Setter Property="Height" Value="2" />
</Style>
Height 的值必须至少为 12,但是与 menuitems 的距离太大。
这里发生了什么?合乎逻辑吗?有解决办法吗?
只需在 Y 轴上缩放分隔符
<Separator>
<Separator.RenderTransform>
<ScaleTransform ScaleY="3" />
</Separator.RenderTransform>
</Separator>
这会将分隔符的高度设置为原始高度的 3 倍。
看到这个:如何:缩放元素
您可以使用该属性在一定程度上调整元素的Margin大小和/或间隔:Separator
<StackPanel>
<Button Width="100" Content="Click me" />
<Separator Margin="50,20" />
<Button Width="100" Content="Click me too" />
</StackPanel>
一般来说,它的长度将填满可用区域,而它的宽度将保持在一个像素,反之亦然,具体取决于它的方向。这将影响其Width:
<StackPanel>
<Button Width="100" Content="Click me" />
<Separator Margin="20" Width="20" />
<Button Width="100" Content="Click me too" />
</StackPanel>
这不会影响Height此方向上的线条,但会影响它占用的总空间:
<StackPanel>
<Button Width="100" Content="Click me" />
<Separator Margin="20" Height="50" />
<Button Width="100" Content="Click me too" />
</StackPanel>
如果您想对线路进行更多控制,那么我建议您改用LineClass。
使用负边距:
<Style x:Key="{x:Static MenuItem.SeparatorStyleKey}" TargetType="{x:Type Separator}">
<Setter Property="Margin" Value="-4,0,-3,0" />
</Style>