如何将 StackPanel 的 MinHeight 设置为其内容的组合高度?
我有一个 StackPanel,里面有几个 CheckBox 控件。调整窗口大小时,如何防止 StackPanel 缩小并遮盖 CheckBox 控件?
<StackPanel Margin="12,89,12,62" Name="stackPanel1">
<CheckBox Name="chkOption1" Width="157" IsChecked="True" Margin="6">Do this thing</CheckBox>
<CheckBox Name="chkOption2" Width="157" IsChecked="True" Margin="6">Do another thing</CheckBox>
<CheckBox Name="chkOption2" Width="157" Margin="6">Do a third thing</CheckBox>
<Button Height="23" Name="btnRunOperations" Click="btnRunOperations_Click" Margin="3">Do Selected Things</Button>
</StackPanel>
编辑:WPF 是否有一个不同的容器控件具有“开箱即用”的这种行为?这似乎是一个非常常见的场景。
I have a StackPanel with several CheckBox controls inside it. How do I prevent the StackPanel from shrinking and obscuring the CheckBox controls when the window is resized?
<StackPanel Margin="12,89,12,62" Name="stackPanel1">
<CheckBox Name="chkOption1" Width="157" IsChecked="True" Margin="6">Do this thing</CheckBox>
<CheckBox Name="chkOption2" Width="157" IsChecked="True" Margin="6">Do another thing</CheckBox>
<CheckBox Name="chkOption2" Width="157" Margin="6">Do a third thing</CheckBox>
<Button Height="23" Name="btnRunOperations" Click="btnRunOperations_Click" Margin="3">Do Selected Things</Button>
</StackPanel>
EDIT: Does WPF have a different container control that has this behavior "out of the box"? This seems like a really common scenario.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,我想您可以将 stackpanel 的 MinimumHeight 设置为适当的值,可以是硬编码的,也可以计算为内部所有元素的高度之和。
Well, I guess you could set the MinimumHeight of the stackpanel to an appropriate value, either hardcoded, either calculated as the sum of the heights of all elements within.
您可以使用绑定和自定义转换器,转换器会为您计算值。
you could use a binding and a custom converter where the converter calculates the value for you.
您应该将 StackPanel 包装在 ScrollViewer 中。默认情况下,它将请求显示其所有子项所需的高度。
You should wrap your StackPanel in a ScrollViewer. By default it will request to be as tall as needed to display all it's children.