【问题标题】:ScrollViewer That Contains a Grid Snaps Back to the Top When Let Go放开时包含网格的 ScrollViewer 会弹回顶部
【发布时间】:2013-11-07 09:01:45
【问题描述】:

我正在使用 ScrollViewer 来启用它包含的 Grid 可滚动。但是,当我向下滚动后松开时,它会自动滚动回 Grid 的顶部。

<ScrollViewer>

    <Grid ShowGridLines="false" MinHeight="700">
        <Grid.RowDefinitions>
            <RowDefinition Height="1" /> 
            <RowDefinition Height="{Binding Pivot1Rows[0].RowHeight}" />
            <RowDefinition Height="1" />
            <RowDefinition Height="{Binding Pivot1Rows[1].RowHeight}" /> 
            <RowDefinition Height="1" />
            <RowDefinition Height="{Binding Pivot1Rows[2].RowHeight}" />
            <RowDefinition Height="1" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="2*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <!-- Stackpanels for each row/column combo here -->
     </Grid>

</ScrollViewer>

知道我需要添加/更改什么以确保网格中向下滚动到的位置即使在我放手后也能保持不变?

【问题讨论】:

  • 愚蠢的我......正要说:它工作......但后来看到手机 8 :) 如果它有任何舒适,它适用于 WPF 和 Windows :)

标签: c# xaml windows-phone-8


【解决方案1】:

您必须将 ScrollViewer 的高度设置为小于 Grid 的高度。如果 ScrollViewer 比它的孩子大,孩子总是会反弹回原来的位置。

【讨论】:

  • 这有助于但没有完全解决问题。我将 ScrollViewer 的高度设置为 700,将 Grid 的高度设置为 800。我可以向下滚动一点,滚动条的位置将保持不变。但是,如果我尝试向下滚动到 Grid 的最底部,它仍然会稍微回弹。也就是说,它不会重新回到 Grid 的顶部,而是会稍微跳跃,导致 Grid 底部的内容不可见。有什么想法吗?
  • 试着玩弄高度,直到你得到你想要的。我认为让网格更大应该是要走的路。
猜你喜欢
  • 2011-11-18
  • 1970-01-01
  • 1970-01-01
  • 2023-04-07
  • 1970-01-01
  • 1970-01-01
  • 2023-04-02
  • 2017-01-02
  • 1970-01-01
相关资源
最近更新 更多