【问题标题】:Remove sticky header on grouped ListView删除分组 ListView 上的粘性标题
【发布时间】:2014-10-15 22:41:24
【问题描述】:

我正在开发一个 Windows Phone 8.1 运行时应用程序,我正在使用 ListView,只有 GroupStyle 及其 HeaderTemplate 集。

一切正常,除了我需要禁用在滚动列表时始终位于顶部的粘性标题,但我找不到需要编辑哪个模板才能完全禁用粘性标题。真正困扰我的一件事是,当我离开页面时,当前页眉消失,并且在同一位置出现空白。

代码很简单:

<CollectionViewSource
    x:Key="cvs"
    IsSourceGrouped="True"
    ItemsPath="GroupItems"
    Source="{Binding Categories}">
</CollectionViewSource>

在Resource,

还有ListView:

<ListView
x:Name="ListView"
IsSwipeEnabled="False"
ItemTemplateSelector="{StaticResource AllGamesViewTemplateSelector}"
ItemsSource="{Binding Source={StaticResource cvs}}"
SelectionMode="None"
ShowsScrollingPlaceholders="True">
    <ListView.GroupStyle>
        <GroupStyle HeaderTemplate="{StaticResource AllGamesViewCategoryTemplate}"/>
    </ListView.GroupStyle>
</ListView>

所以我的问题是如何禁用分组 ListView 上的粘性标题?

【问题讨论】:

  • 我不认为是 GroupStyle,我认为更可能是 ItemsPanel 或 ItemsPresenter。 ItemsPresenter 的 HeaderTransitions 可能是原因。
  • 您找到解决方案了吗?我也遇到了同样的问题

标签: xaml windows-runtime winrt-xaml windows-phone-8.1


【解决方案1】:

我有同样的问题,最后遇到了这个问题:https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.itemsstackpanel.arestickygroupheadersenabled?f=255&MSPPError=-2147217396

在 ListView 的 ItemsPanelTemplate 中设置 AreStickyGroupHeadersEnabled 属性。

<ListView
    x:Name="ListView"
    IsSwipeEnabled="False"
    ItemTemplateSelector="{StaticResource AllGamesViewTemplateSelector}"
    ItemsSource="{Binding Source={StaticResource cvs}}"
    SelectionMode="None"
    ShowsScrollingPlaceholders="True">
    <ListView.GroupStyle>
        <GroupStyle HeaderTemplate="{StaticResource AllGamesViewCategoryTemplate}"/>
    </ListView.GroupStyle>

    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <ItemsStackPanel AreStickyGroupHeadersEnabled="False"/>
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
</ListView>

【讨论】:

    【解决方案2】:

    您应该能够将 ListView 包装在 ScrollViewer 中以防止粘页。

    【讨论】:

    • 但是虚拟化不起作用,这对我来说至关重要,因为我的列表有数百个项目
    【解决方案3】:

    想到的一个解决方案是不在 ListView 中使用分组,只是模拟它。创建一个集合,该集合将保存组的项目和代表标题的占位符项目。然后使用 ListView 的模板选择器将占位符项呈现为标题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-30
      相关资源
      最近更新 更多