Windows应用商店应用程序的ListView:如何使用GroupStyle? [英] Windows Store App ListView: How to use the GroupStyle?

查看:242
本文介绍了Windows应用商店应用程序的ListView:如何使用GroupStyle?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我移植一个Windows Phone应用程序到Windows应用商店,并试图建立一个分组的ListView。有href=\"http://msdn.microsoft.com/en-us/library/windows/apps/hh780627.aspx\"的开发中心和分组rel=\"nofollow\">好文章一个

am porting a Windows Phone App to Windows Store and trying to create a grouped ListView. There is a good article in the Dev Center and grouping the list is no problem. But there are some things I do not understand about the GroupStyle.

从制品的例子使用一个GroupStyleSelector通向以下GroupStyle:

The example from the article uses a GroupStyleSelector that leads to the following GroupStyle:

        <GroupStyle x:Key="listViewGroupStyle">
            <GroupStyle.HeaderTemplate>
                <DataTemplate>
                    <Grid Background="LightGray"  >
                        <TextBlock Text='{Binding Key}' Foreground="Black" Margin="10"
                       Style="{StaticResource SubheaderTextBlockStyle}" />
                    </Grid>
                </DataTemplate>
            </GroupStyle.HeaderTemplate>

            <GroupStyle.Panel>
                <ItemsPanelTemplate>
                    <VariableSizedWrapGrid MaximumRowsOrColumns="3" Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </GroupStyle.Panel>
        </GroupStyle>

GroupStyle.HeaderTemplate的目的是显而易见的,并且可以在运行的应用程序可以直接观察到这种模板的变化。

The purpose of GroupStyle.HeaderTemplate is obvious and changes on this template can be directly observed in the running app.

但是,什么是GroupStyle.Panel好?该文档

But what is GroupStyle.Panel good for? The docs says:

获取或设置创建用于布局的项目面板中的模板。

Gets or sets a template that creates the panel used to lay out the items.

好吧,但是不管我怎么变ItemsPanelTemplate(BackgroundColor中,方向等),列表中不中正在运行的应用程序更改。

Ok, but no matter how I change ItemsPanelTemplate (BackgroundColor, Orientation, etc.), the List does not change in the running app.

此外有GroupStyle.ContainerStyle未在实施例中使用。如果添加到GroupStyle这已在运行的应用程序名单上没有influece为好。

Additionally there is GroupStyle.ContainerStyle which is not used in the Example. If add this to the GroupStyle this has no influece on the list in the running app as well.

那么,什么是GroupStyle.Panel和GroupStyle.ContainerStyle好?如何在正确使用?

So, what are GroupStyle.Panel and GroupStyle.ContainerStyle good for? How are the used correctly?

推荐答案

我发现,你需要设置的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>

这篇关于Windows应用商店应用程序的ListView:如何使用GroupStyle?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆