Czy ktoś może mi dać wskazówki, jak wykonać grupowanie w GridView dla aplikacji Metro, jak pokazano na zrzucie poniżej.Grupowanie GridView w Windows 8 Metro App
Ten zrzut ekranu jest z Developer Resources for Windows Metro Apps, ale niestety nie ma opisu jak ją osiągnąć.
Mam następujący fragment kodu:
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>
...
C#:
W Code-Behind I wykonaj następujące czynności w metodzie OnNavigateTo:
List<string> strList = new List<string>() {
"Red", "Red", "Red", "Red", "Red", "Red",
"Green", "Green","Green","Green","Green",
"Blue","Blue","Blue","Blue" };
var groupedList = from s in strList
group s by s into g
orderby g.Key
select g;
cvs.Source = groupedList;
Bez względu na to, co robię, nie jestem w stanie pogrupować elementów na liście kontynuowanej, tak jak w Screenshot. Kod ten tworzy osobne listy zgrupowane obok siebie.
Przykład dostarczania MSDN nie jest taki sam jak użytkownik prosi o ... – toroveneno