且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Windows应用商店应用程序的ListView:如何使用GroupStyle?

更新时间:2023-02-05 22:02:40

我发现,你需要设置的ListView的ItemsPanel了。默认情况下,ItemsStackPanel被使用,这似乎并没有允许在分组的ListView任何自定义面板。当设置ItemsPanel到VirtualizingStackPanel,自定义面板应用,但头是不发粘了。似乎有什么东西破碎了当前的ListView / ItemsStackPanel实施和我们没有源代码访问这很难说。

I found out that you need to set the ItemsPanel of the ListView, too. By default the ItemsStackPanel is used and that doesn't seem to allow any custom panel in a grouped ListView. When setting the ItemsPanel to a VirtualizingStackPanel, the custom panel is applied, BUT the headers are not sticky anymore. It seems that there is something broken about the current ListView/ItemsStackPanel implementation and as we do not have source access it's hard to tell what.

<ListView 
        ItemsSource="{Binding Source={StaticResource namesSource}}"
        >
            <ListView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Key}" Foreground="Yellow" FontSize="{ThemeResource HubHeaderFontSize}" Margin="6" />
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                    <GroupStyle.Panel>
                    <ItemsPanelTemplate>
                        <controls:WrapPanel />
                    </ItemsPanelTemplate>
                </GroupStyle.Panel>
                </GroupStyle>
            </ListView.GroupStyle>
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <!--<ItemsWrapGrid FlowDirection="LeftToRight"  Orientation="Vertical"/>-->
                    <VirtualizingStackPanel Orientation="Vertical"/>
                    <!--<ItemsStackPanel Orientation="Vertical"/>-->
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid Background="AliceBlue" Margin="3,0">
                        <TextBlock Text="{Binding}" Foreground="Black" Margin="4,2"/>
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>