WPF - 扩展器中的滚动列表框
我有一个 Expander
,我想在其中添加 ListBox
。当我打开 Expander
时,ListBox
只是扩展到屏幕之外(而不是扩展以填充可用的内容然后滚动)。
这是我的 XAML:
<DockPanel Margin="266.25,0,455,12" Name="dockPanel1">
<StackPanel>
<Expander Header="expander1" Name="expander1" Width="150" HorizontalAlignment="Left">
<Grid>
<Label>Testing</Label>
<ScrollViewer>
<ListBox Name="lstBox" FontSize="14" SelectionChanged="lstBox_SelectionChanged" />
</ScrollViewer>
</Grid>
</Expander>
<Expander Header="expander2" Name="expander2" Width="150" HorizontalAlignment="Left">
<Grid >
</Grid>
</Expander>
</StackPanel>
</DockPanel>
当 Expander1
打开时,它只是扩展到 ListBox
的大小(超出屏幕)。如果我在网格上设置尺寸(Height="275"
),那么它不会随窗口调整大小。
我希望它拉伸到窗口的大小,但仅此而已。有办法做到这一点吗?
I have an Expander
that I want to have a ListBox
in. When the I open the Expander
, the ListBox
just expands off the screen (rather than expanding to fill what is available and then scrolling).
Here is my XAML:
<DockPanel Margin="266.25,0,455,12" Name="dockPanel1">
<StackPanel>
<Expander Header="expander1" Name="expander1" Width="150" HorizontalAlignment="Left">
<Grid>
<Label>Testing</Label>
<ScrollViewer>
<ListBox Name="lstBox" FontSize="14" SelectionChanged="lstBox_SelectionChanged" />
</ScrollViewer>
</Grid>
</Expander>
<Expander Header="expander2" Name="expander2" Width="150" HorizontalAlignment="Left">
<Grid >
</Grid>
</Expander>
</StackPanel>
</DockPanel>
When Expander1
is opened then it just expands to the size of the ListBox
(off the screen). If I put a size on the grid (Height="275"
), then it does not resize with the window.
I want it to stretch to the size of the window, but no more. Is there a way to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要设置 ScrollViewer 的 Height 属性,否则它将与其子级的大小相同。以下是一些更新的 XAML:
You need to set the Height property of ScrollViewer otherwise it will be the same size as it's child. Here is some updated XAML: