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>
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?
The
StackPanelis changing the orientation of theSeparatorsomehow. Note that if you explicitly tell theSeparatorto be 20 units wide, theSeparatorwill be a horizontal line instead of a vertical line. That’s part of what’s going on.If you apply a
LayoutTransformto theSeparator, it undoes whatever theStackPanelis doing.I don’t understand the need for a
StackPanel, though.