如何在 Silverlight 中将 ScrollBar 添加到 StackPanel?
我有一个 Grid,3 x 3(3 个 RowDefinitions 和 3 个 ColumnDefinitions)。我希望其中一个网格单元格中的一些内容(StackPanel
)能够滚动。我相当确定这是可能的,但我不知道如何实现。我尝试将 ScrollViewers
和 ScrollBar
控件添加到我想要滚动的网格单元中,但这通常最终会为整个页面创建滚动。
编辑: 更具体地说,我的问题是如何在 StackPanel 上滚动。如果我遇到的问题在这里,则举个例子:
<Grid x:Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid>
<TextBlock FontSize="16">1,1</TextBlock>
</Grid>
<Grid Grid.Column="1">
<TextBlock FontSize="16">1,2</TextBlock>
</Grid>
<Grid Grid.Row="1">
<TextBlock FontSize="16">2,1</TextBlock>
</Grid>
<Grid Grid.Column="1" Grid.Row="1">
<StackPanel>
<TextBlock>Title</TextBlock>
<Grid>
<ScrollViewer>
<StackPanel>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
</StackPanel>
</ScrollViewer>
</Grid>
</StackPanel>
</Grid>
</Grid>
I have a Grid
, 3 by 3 (3 RowDefinitions and 3 ColumnDefinitions). I want some content (a StackPanel
) in one of those grid cells to scroll. I'm fairly sure this is possible but I cannot figure out how. I've tried adding ScrollViewers
and ScrollBar
controls to the grid cell I want to scroll, but this usually ends up creating scrolling for the entire page.
Edit:
My issue is more specificlly how I can get scrolling over a StackPanel
. An example if the issue I am having is here:
<Grid x:Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid>
<TextBlock FontSize="16">1,1</TextBlock>
</Grid>
<Grid Grid.Column="1">
<TextBlock FontSize="16">1,2</TextBlock>
</Grid>
<Grid Grid.Row="1">
<TextBlock FontSize="16">2,1</TextBlock>
</Grid>
<Grid Grid.Column="1" Grid.Row="1">
<StackPanel>
<TextBlock>Title</TextBlock>
<Grid>
<ScrollViewer>
<StackPanel>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
<TextBlock FontSize="32">2,2</TextBlock>
</StackPanel>
</ScrollViewer>
</Grid>
</StackPanel>
</Grid>
</Grid>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
StackPanel 认为其内容具有无限的空间。要滚动堆栈面板,您必须对某些东西施加高度限制 - 最有可能的是堆栈面板的网格父级。
StackPanel treats its content has having infinite space. To scroll the stackpanel, you're going to have to put a height constraint on something - the grid parent of the stackpanel, most likely.