问题描述
论坛,
所以我有一个ListView,我在StackPanel中使用,直到遇到ListView从我的页面底部运行的情况。  我可以毫不费力地将其切换到网格,但我很难理解为什么ListView(在项目模板的一个
中设置样式)在两者之间表现得如此不同。 当我有这样的XAML:
So I have a ListView, and I was using in a StackPanel until I ran into a situation in which the ListView ran off the bottom of my Page. I can switch this to a Grid without much trouble, but I struggle to understand why the ListView (as styled in one of the project templates) behaves so much differently between the two. When I have XAML like this:
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock>Winner winner</TextBlock>
<ListView Grid.Row="1">
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="1"/>
<TextBlock Text="2"/>
</ListView>
</Grid>
布局显示文本行,项目列表滚动条 r如预期&NBSP;但是,当我将其更改为使用StackPanel时,如下所示:
The layout appears with the line of text and the list of items with a scroll bar as expected. However, when I change it to use a StackPanel, like this:
<StackPanel Grid.Row="1">
<TextBlock>Winner winner</TextBlock>
<ListView>
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="1"/>
<TextBlock Text="2"/>
</ListView>
</StackPanel>
我得到的情况是ListView只是向下跑过页面的边界,没有滚动条。我已经看过一些关于使用VirtualizingStackPanels设置ListViews样式的讨论,但是我不确定这些讨论是如何应用的,如果
他们这样做的话。 我想理解为什么布局会像这样;有人可以解释为什么StackPanel允许这种情况发生吗?
I get a situation in which the ListView just runs downward past the bounds of the page, with no scroll bar. I've looked at some previous discussions about styling ListViews with VirtualizingStackPanels, but I'm not sure how those discussions apply here, if they do. I want to understand why the layout behaves like this; can someone please explain why the StackPanel lets this happen?
推荐答案
当你将Listview添加到网格的Row2时,它会延伸到网格边界之外,因此需要一个滚动条来进行访问。
When you add the Listview to Row2 of the the grid, it extends outside of the grid boundaries and therefore needs a scrollbar for accessibility.
在第二个示例中,您已经对一个无限大小的容器 - stackpanel进行了十分转换。 这意味着该stackpanel内的对象将自己堆叠而不考虑高度(给定垂直方向)。 因此,没有
边界可以跨越,并且列表视图不会生成滚动条以允许在屏幕外查看。
In the second sample, you've decalred a container of indefinite size - the stackpanel. That means that the objects inside that stackpanel will stack themselves without regard to the height (given a vertical orientation). Therefore, there's no boundary to cross, and the listview does not generate a scrollbar to allow for off-screen viewing.
这篇关于StackPanels中的ListViews与网格中的ListViews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!