0

この質問を解決する方法がわからないので、今日あなたのところに来ました。Gridview をアルファベット順に並べたいのですが、これは簡単です。しかし、最初の文字の各グループの前に文字のビネットを追加したいと思います。Windows 8の「お問い合わせ」アプリのような機能。

このような :

 - A :
 aaaa
 aaaann
 aananana
- B :
bbbaaaa
bbbabbbb
bbbaccc
 -C : 
cccc...

これはグリッドビューのコードです。このグリッドビューにデータをバインドし、文字の各グループの間にグループの文字を含む別のビネットを追加したいと考えています。

<Grid>
                    <DataTemplate>
                        <GridView ItemsSource="{Binding Path=Data}" 
                                  IsItemClickEnabled="True" SelectionMode="None">
                            <GridView.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <VariableSizedWrapGrid Orientation="Vertical" ItemWidth="280" />
                                </ItemsPanelTemplate>
                            </GridView.ItemsPanel>
                        </GridView>
                    </DataTemplate>
        </Grid>

アイデアがあれば?御時間ありがとうございます、

よろしく。

4

1 に答える 1

3

Bingoogle で答えが見つかります。http://code.msdn.microsoft.com/windowsapps/GroupedGridView-77c59e8e

SampleDataSourceサンプル アプリのには、次のメソッドがあります。

    internal List<GroupInfoList<object>> GetGroupsByLetter() 
    { 
        List<GroupInfoList<object>> groups = new List<GroupInfoList<object>>(); 

        var query = from item in Collection 
                    orderby ((Item)item).Title 
                    group item by ((Item)item).Title[0] into g 
                    select new { GroupName = g.Key, Items = g }; 
        foreach (var g in query) 
        { 
            GroupInfoList<object> info = new GroupInfoList<object>(); 
            info.Key = g.GroupName; 
            foreach (var item in g.Items) 
            { 
                info.Add(item); 
            } 
            groups.Add(info); 
        } 

        return groups; 

    } 
} 

Scenario2.xaml.cs を見ると、そのメソッドが呼び出され、結果が次のように割り当てられますCollectionViewSource

List<GroupInfoList<object>> dataLetter = _storeData.GetGroupsByLetter(); 

// sets the CollectionViewSource in the XAML page resources to the data groups 
cvs2.Source = dataLetter; 

cvs2ページの XAML コードでリソースとして定義されます。

<common:LayoutAwarePage.Resources> 
    <CollectionViewSource x:Name="cvs2" IsSourceGrouped="true" /> 
</common:LayoutAwarePage.Resources> 

次に、をそのようGridViewに使用し、グループとアイテムのを定義します。CollectionViewSourceItemsCollectionDataTemplates

        <GridView x:Name="ItemsByLetter"  VerticalAlignment="Bottom"  
                  Height="325" 
                  Width="1150" 
                  ItemsSource="{Binding Source={StaticResource cvs2}}" 
                  ShowsScrollingPlaceholders="False" 
                  ContainerContentChanging="ItemsByLetter_ContainerContentChanging" 
                  BorderBrush="{StaticResource ApplicationForegroundThemeBrush}" BorderThickness="1"> 

            <GridView.ItemsPanel> 
                <ItemsPanelTemplate> 
                    <ItemsWrapGrid GroupHeaderPlacement="Left" /> 
                </ItemsPanelTemplate> 
            </GridView.ItemsPanel> 
            <GridView.ItemTemplate> 
                <DataTemplate> 
                    <local:ItemViewer/> 
                </DataTemplate> 
            </GridView.ItemTemplate> 

            <GridView.GroupStyle> 
                <GroupStyle> 
                    <GroupStyle.HeaderTemplate> 
                        <DataTemplate> 
                            <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}" Margin="10"> 
                                <TextBlock Text='{Binding Key}' Foreground="{StaticResource ApplicationForegroundThemeBrush}" FontSize="25" Margin="5" /> 
                            </Grid> 
                        </DataTemplate> 
                    </GroupStyle.HeaderTemplate> 
                </GroupStyle> 
            </GridView.GroupStyle> 
        </GridView> 
于 2013-10-17T15:39:29.890 に答える