【发布时间】:2012-08-26 10:40:53
【问题描述】:
我有一个字典,其中键是字符串,元素是列表
我想用 element 中的元素从每个键创建一个组。但是不知道怎么弄
<Page.Resources>
<!--
Collection of grouped items displayed by this page, bound to a subset
of the complete item list because items in groups cannot be virtualized
-->
<CollectionViewSource
x:Name="groupedItemsViewSource"
IsSourceGrouped="true"
/>
</Page.Resources>
<GridView ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
IsSwipeEnabled="True">
<GridView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding name}"
Foreground="White" />
</DataTemplate>
</GridView.ItemTemplate>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="Test 123" Foreground="Gold" />
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid Orientation="Vertical" />
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</GridView.GroupStyle>
</GridView>
在循环中我创建字典
groups.Add(this.letters[i], items);
然后我有
groupedItemsViewSource.Source = groups;
但我什么也得不到。我应该如何更正此问题以将键作为组标题,并将每个列表作为此网格中的元素列表??
// 编辑
好的,我发现制作 List> 而不是 Dictionary 更好。我现在得到 3 个组标题(因为我的列表中有 3 个列表)但没有项目。 IMO 这比第一种方法更好
// 编辑 2 我没有看到项目,因为背景和前景都是白色的。愚蠢的我:) 但现在我有最后一个问题要解决。如何动态设置群组标题?
【问题讨论】:
-
不要改变你的问题。它使我们向移动的目标射击。
-
@Erno 抱歉,我只是想提供尽可能多的信息
-
这不是更多信息,这只是另一个问题。想象一下,有些问题与您添加的最后一个问题相同。他偶然发现这个问题的机会有多大?
标签: c# xaml windows-8 windows-runtime winrt-xaml