WPF 列表框不受窗口限制
我正在开发一个复杂的应用程序,并且遇到列表框不受窗口高度限制的问题。这是它的简化版本。我怎样才能让这个列表框正确地受到窗口的限制?现在,底部滚动按钮位于屏幕之外,直到窗口足够大以容纳整个列表框之前才能看到。我需要找到一个使列表框始终有界的解决方案,因为我必须通过 ScaleTransform 实现缩放。
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300" />
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid Name="stack">
<Grid.LayoutTransform>
<ScaleTransform
ScaleX="{Binding ElementName=slider, Path=Value}"
ScaleY="{Binding ElementName=slider, Path=Value}" />
</Grid.LayoutTransform>
<WrapPanel HorizontalAlignment="Left">
<Expander IsExpanded="False" Width="300">hey</Expander>
<Expander IsExpanded="True" VerticalAlignment="Stretch" ClipToBounds="True">
<Grid>
<ListBox >
<Button>hey</Button>
<!-- just add a lot more of these to see the problem -->
<Button>hey</Button>
</ListBox>
</Grid>
</Expander>
</WrapPanel>
</Grid>
<Slider Grid.Column="1" Name="slider" Minimum="1" Maximum="4" Value="1" />
</Grid>
I'm working on a complex application, and I'm having an issue with a listbox not being bounded by the window height. Here's a simplified version of what it looks like. How would I get this listbox to correctly be bounded by the window? Right now, the bottom scroll button is off the screen and cannot be seen until the window is big enough to fit the entire listbox. I need to find a solution that makes the listbox always bounded because I have to implement zooming via a ScaleTransform.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300" />
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid Name="stack">
<Grid.LayoutTransform>
<ScaleTransform
ScaleX="{Binding ElementName=slider, Path=Value}"
ScaleY="{Binding ElementName=slider, Path=Value}" />
</Grid.LayoutTransform>
<WrapPanel HorizontalAlignment="Left">
<Expander IsExpanded="False" Width="300">hey</Expander>
<Expander IsExpanded="True" VerticalAlignment="Stretch" ClipToBounds="True">
<Grid>
<ListBox >
<Button>hey</Button>
<!-- just add a lot more of these to see the problem -->
<Button>hey</Button>
</ListBox>
</Grid>
</Expander>
</WrapPanel>
</Grid>
<Slider Grid.Column="1" Name="slider" Minimum="1" Maximum="4" Value="1" />
</Grid>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试以下代码:
try the following code: