【问题标题】:Strange scrollbar behaviour奇怪的滚动条行为
【发布时间】:2012-10-21 07:36:17
【问题描述】:

在我的应用程序中,我有一个非常奇怪的滚动条行为:底部滚动条在滚动时会随机改变其大小。我使用了一个 GridView,里面有很多项目(支持代码):

<GridView
  Margin="0,-3,0,0"
  Padding="116,0,40,46">

  <GridView.ItemsPanel>
     <ItemsPanelTemplate>
         <VirtualizingStackPanel Orientation="Horizontal"/>
     </ItemsPanelTemplate>
  </GridView.ItemsPanel>
  <GridView.GroupStyle>
     <GroupStyle>
         <GroupStyle.HeaderTemplate>
             <DataTemplate>
                <!-- Data Template here -->         
             </DataTemplate>
         </GroupStyle.HeaderTemplate>
         <GroupStyle.Panel>
            <ItemsPanelTemplate>
                <VariableSizedWrapGrid ItemWidth="250" ItemHeight="250" Orientation="Vertical" Margin="0,0,80,0"  MaximumRowsOrColumns="4"/>
            </ItemsPanelTemplate>
         </GroupStyle.Panel>
     </GroupStyle>
  </GridView.GroupStyle>
</GridView>

我还发现,如果我删除填充,行为就会消失。我可以将填充的值设置为边距,但是滚动条也有边距,看起来真的很难看...

我该如何改变呢? - 我注意到其他几个应用程序也有这个问题...

感谢您的帮助!

【问题讨论】:

    标签: xaml windows-8 microsoft-metro scrollbar


    【解决方案1】:

    您所看到的(“随机滚动条大小变化”)是网格内项目虚拟化的结果(实际上是在 VirtualisingStackPanel 内)。随着网格视图中的虚拟化容器加载更多显示项目,滚动查看器会根据其内容调整大小。

    如果该行为导致您出现问题,请尝试覆盖项目面板模板并为您的元素指定一个非虚拟化容器。

    【讨论】:

    • 感谢您的留言。你所描述的听起来很适合我的问题。有趣的是,当滚动条全部位于左侧时,滚动条会更长,而当您开始向右滚动时,滚动条会变短。然后它保持它的大小......我怎样才能达到你的建议?谢谢。
    • 也许只是将您的 VirtualisingStackPanel 更改为常规 StackPanel?
    • 这个答案对我来说很划算——我使用了一个虚拟化面板,认为这只是最佳实践;但滚动条的行为很奇怪。用 StackPanel 替换它就可以了。同样,此特定页面上的项目也不多。
    【解决方案2】:

    我认为您应该将 Grid 放在 ScrollViewer 标记中。

    <ScrollViewer Height="200" Width="200" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
    <GridView
      Margin="0,-3,0,0"
      Padding="116,0,40,46">
    
      <GridView.ItemsPanel>
         <ItemsPanelTemplate>
             <VirtualizingStackPanel Orientation="Horizontal"/>
         </ItemsPanelTemplate>
      </GridView.ItemsPanel>
      <GridView.GroupStyle>
         <GroupStyle>
             <GroupStyle.HeaderTemplate>
                 <DataTemplate>
                    <!-- Data Template here -->         
                 </DataTemplate>
             </GroupStyle.HeaderTemplate>
             <GroupStyle.Panel>
                <ItemsPanelTemplate>
                    <VariableSizedWrapGrid ItemWidth="250" ItemHeight="250" Orientation="Vertical" Margin="0,0,80,0"  MaximumRowsOrColumns="4"/>
                </ItemsPanelTemplate>
             </GroupStyle.Panel>
         </GroupStyle>
      </GridView.GroupStyle>
    </GridView>
     </ScrollViewer>
    

    尝试根据您的应用进行调整。 有关属性和事件here,请参阅 ScrollViewer。 做点新事here

    【讨论】:

    • 嗨。谢谢你的帖子。不幸的是,这在“SemanticZoom.ZoomedInView”中是不可能的。根据错误消息,“ISemanticZoomInformation”类型是预期的(GridView 而不是 ScrollViewer)。你有什么建议如何处理吗?谢谢!
    【解决方案3】:

    @ZombieSheep 解释的内容实际上是非常正确的,但这种情况仅在您使用 gridview/listview 的增量加载时才会发生,但是在您的特定情况下,如果您可以设置正确的 gridview 的 padding 属性,滚动条会改变大小并将填充值 (Padding="116,0,40,46") 设置为 0 或小于您可以看到差异的值,可能不需要放置scrollviewer里面的gridview

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-28
      • 1970-01-01
      • 2016-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多