小编Edm*_*ari的帖子

在Windows 8 Metro App中对GridView进行分组

有人可以给我一些提示如何在GridView for Metro Apps中完成分组,如下面的屏幕截图所示.

缩小图像

此屏幕截图来自Windows资源管理器开发人员资源,但遗憾的是没有说明如何完成它.

我有以下代码片段:

XAML:

    ...

    <Page.Resources>
        <CollectionViewSource x:Name="cvs" IsSourceGrouped="true"/>
    </Page.Resources>

    <Grid Background="{StaticResource DefaultBackground}">

        <GridView x:Name="DefaultGridView" ItemsSource="{Binding Source={StaticResource cvs}}">
            <GridView.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Rectangle Fill="{Binding}" Width="100" Height="100" Margin="0 0 5 0"/>
                    </StackPanel>
                </DataTemplate>
            </GridView.ItemTemplate>

            <GridView.GroupStyle>
                <GroupStyle>

                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <TextBlock Text='{Binding Key}' Foreground="Gray" Margin="5" FontSize="30" FontFamily="Segoe UI Light" />
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>

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

                </GroupStyle>
            </GridView.GroupStyle>


            <GridView.ItemsPanel>
                <ItemsPanelTemplate>
                   <StackPanel Orientation="Vertical" />
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>


        </GridView>

    </Grid>

...
Run Code Online (Sandbox Code Playgroud)

C#:

在Code-Behind中,我在OnNavigateTo方法中执行以下操作:

        List<string> strList …
Run Code Online (Sandbox Code Playgroud)

c# wpf grouping gridview microsoft-metro

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

c# ×1

gridview ×1

grouping ×1

microsoft-metro ×1

wpf ×1