我有一本字典,其中键是一个String和元素是一个列表如何创建GridView控件从字典
我想从与元素元素每个键创建一个组。但我不`吨知道如何使它
<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这是比更好的办法第一
// EDIT 2 我didn`t看到物品引起的背景和前景是白色的。愚蠢的我:)但现在我有最后一个问题来解决。如何动态设置组标题?如果你想
不要改变你的问题。它使我们在一个移动的目标上开枪。 –
@Erno对不起,我只是尽量给尽可能多的信息,我可以 – Fixus
这不是更多的信息,这只是另一个问题。想象一下,有些人与你添加的最后一个人有同样的问题。他在这个问题上绊倒了什么? –