WPF堆栈面板
简单的问题,我有一个带有工具栏和列表框的堆栈面板,我希望列表框填充剩余空间,但它不会。这就是我现在所拥有的。
<Window x:Class="TestClientMainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Testing client" Height="350" Width="525"
DataContext="{StaticResource ResourceKey=TheViewModel}" Background="#FFD4BFBF">
<Grid>
<StackPanel HorizontalAlignment="Stretch" Name="stackPanel1" VerticalAlignment="Stretch">
<ToolBar Height="26" Name="toolBar1" />
<ListBox Name="listBox1" VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" MinHeight="{Binding ElementName=stackPanel1, Path=Height}" Height="99" />
</StackPanel>
</Grid>
Easy question, I have a stack panel with a toolbar and listbox, I want the listbox to fill the remaining space, but it won't. Here's what I have at the moment.
<Window x:Class="TestClientMainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Testing client" Height="350" Width="525"
DataContext="{StaticResource ResourceKey=TheViewModel}" Background="#FFD4BFBF">
<Grid>
<StackPanel HorizontalAlignment="Stretch" Name="stackPanel1" VerticalAlignment="Stretch">
<ToolBar Height="26" Name="toolBar1" />
<ListBox Name="listBox1" VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" MinHeight="{Binding ElementName=stackPanel1, Path=Height}" Height="99" />
</StackPanel>
</Grid>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试使用
DockPanel
而不是StackPanel
。这样,您可以将LastChildFill
设置为 true,并且您的ListBox
作为最后一个包含的元素,将拉伸以填充其剩余空间:Try using a
DockPanel
instead of aStackPanel
. That way you can setLastChildFill
to true and yourListBox
, being the last contained element, will stretch to fill up its remaining space:尝试使用
DockPanel
,将ToolBar
停靠在顶部或底部,并将LastChildFill
属性设置在DockPanel
上为true
。Try using a
DockPanel
, with theToolBar
docked to the top or bottom and theLastChildFill
property on theDockPanel
set totrue
.使用 DockPanel 而不是 StackPanel 并将 LastChildFill 属性设置为 true。那应该可以解决问题。
Use DockPanel instead of StackPanel and set LastChildFill attribute to true. That should do the trick.
StackPanel 不会轻易被说服做你想做的事。
我会使用网格代替。
A StackPanel will not be easily convinced to do what you want.
I would use a Grid instead.