如何在 Silverlight 中将 ScrollBar 添加到 StackPanel?

发布于 2024-08-30 01:25:51 字数 2400 浏览 5 评论 0原文

我有一个 Grid,3 x 3(3 个 RowDefinitions 和 3 个 ColumnDefinitions)。我希望其中一个网格单元格中的一些内容(StackPanel)能够滚动。我相当确定这是可能的,但我不知道如何实现。我尝试将 ScrollViewersScrollBar 控件添加到我想要滚动的网格单元中,但这通常最终会为整个页面创建滚动。

编辑: 更具体地说,我的问题是如何在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偏爱你一生 2024-09-06 01:25:51

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文