WPF 工具栏分隔符在 StackPanel 内时缩小为无 [英] WPF ToolBar Separator shrinks to nothing when inside a StackPanel
问题描述
鉴于非常简单的 wpf 应用程序
Given the very simple wpf app
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="800">
<Grid>
<ToolBar Height="50" >
<MenuItem Header="Test1" />
<MenuItem Header="Test2" />
<StackPanel Orientation="Horizontal">
<Separator />
<MenuItem Header="Test3" />
<MenuItem Header="Test4" />
<MenuItem Header="Test5" />
</StackPanel>
</ToolBar>
</Grid>
</Window>
Separator 元素缩小为无.如果我将 Separator 放在 StackPanel 开始之前,它就会显示出来.为什么会发生这种情况?是否有可以在某处应用的样式设置来避免这种情况?
The Separator element shrinks to nothing. If I put the Separator just before the StackPanel begins, it will show up. Why does this happen? Is there a style setting that can be applied somewhere to avoid this?
推荐答案
StackPanel
以某种方式改变了 Separator
的方向.请注意,如果您明确告诉 Separator
为 20 个单位宽,Separator
将是一条水平线而不是一条垂直线.这是正在发生的事情的一部分.
The StackPanel
is changing the orientation of the Separator
somehow. Note that if you explicitly tell the Separator
to be 20 units wide, the Separator
will be a horizontal line instead of a vertical line. That's part of what's going on.
如果您将 LayoutTransform
应用到 Separator
,它会撤消 StackPanel
正在执行的任何操作.
If you apply a LayoutTransform
to the Separator
, it undoes whatever the StackPanel
is doing.
<Separator>
<Separator.LayoutTransform>
<RotateTransform
Angle="90" />
</Separator.LayoutTransform>
</Separator>
不过,我不明白需要 StackPanel
.
I don't understand the need for a StackPanel
, though.
这篇关于WPF 工具栏分隔符在 StackPanel 内时缩小为无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!