边框可以在不明确设置宽度的情况下填充 Stackpanel 的空间吗?
下面是一些 xaml,它显示一个并排包含两个边框的 Stackpanel。我想让第二个边框填满Stackpanel的剩余区域,这样Stackpanel的红色背景就看不到了。但我现在看到了除了在 Border 上设置显式宽度之外的方法。可以在不设置显式宽度的情况下以某种方式完成吗?
<StackPanel Width="300" Background="Red" Orientation="Horizontal">
<Border Width="100" Background="White">
<TextBlock Text="Hello"/>
</Border>
<Border Background="Green">
<TextBlock Text="World"/>
</Border>
</StackPanel>
Here is some xaml that displays a Stackpanel containing two Borders side by side. I want to make the second Border fill up the remaining area of the Stackpanel so that the red background of the Stackpanel can't be seen. But I see now way to do it other than setting an explicit width on the Border . Can it be done somehow without setting an explicit width?
<StackPanel Width="300" Background="Red" Orientation="Horizontal">
<Border Width="100" Background="White">
<TextBlock Text="Hello"/>
</Border>
<Border Background="Green">
<TextBlock Text="World"/>
</Border>
</StackPanel>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不使用 Stackpanel,不。 Stackpanel 不限制其子级的宽度。您应该为此布局使用 Dockpanel 或 Grid。
像这样的东西
Not with a Stackpanel, no. The Stackpanel does not limit the width of its children. You should use either a Dockpanel or a Grid for this Layout.
Something like