我希望GroupBox高度可以调整窗口大小,如果内容的高度较大,则显示ScrollViewer。但它将大小设置为大小内容或MaxHeight(如果设置)。
<StackPanel>
<GroupBox>
<ScrollViewer VerticalAlignment="Top" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Visible">
<StackPanel>
<Button VerticalAlignment="Top">Button</Button>
<Button VerticalAlignment="Top">Button</Button>
<Button VerticalAlignment="Top">Button</Button>
<Button VerticalAlignment="Top">Button</Button>
<Button VerticalAlignment="Top">Button</Button>
<Button VerticalAlignment="Top">Button</Button>
<Button VerticalAlignment="Top">Button</Button>
<Button VerticalAlignment="Top">Button</Button>
<Button VerticalAlignment="Top">Button</Button>
<Button VerticalAlignment="Top">Button</Button>
<Button VerticalAlignment="Top">Button</Button>
<Button VerticalAlignment="Top">Button</Button>
<Button VerticalAlignment="Top">Button</Button>
<Button VerticalAlignment="Top">Button</Button>
<Button VerticalAlignment="Top">Button</Button>
<Button VerticalAlignment="Top">Button</Button>
<Button VerticalAlignment="Top">Button</Button>
<Button VerticalAlignment="Top">Button</Button>
<Button VerticalAlignment="Top">Button</Button>
<Button VerticalAlignment="Top">Button</Button>
</StackPanel>
</ScrollViewer>
</GroupBox>
</StackPanel>
答案 0 :(得分:0)
我发现如果将外部StackPanel替换为DockPanel它将起作用。
<DockPanel>
<GroupBox DockPanel.Dock="Top">
<ScrollViewer VerticalAlignment="Top" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Visible">
<StackPanel>
<Button VerticalAlignment="Top">Button</Button>