我的 Gridview 运行良好,但有一个问题我一段时间以来都想不通。Gridview 每组显示不超过 2 个项目。ItemTemplate 和传入的 List 是有效的。
<GridView x:Name="mainGridView" ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
SelectionMode="Multiple" IsItemClickEnabled="True" ItemClick="GridView_ItemClick_1" Grid.Row="1"
Margin="0,-3,0,0" Padding="116,25,40,46"
FontFamily="Global User Interface" ItemTemplate="{StaticResource mainPageTileTemplates}"
ItemContainerStyle="{StaticResource GridViewItemStyleStretch}" SelectionChanged="Item_selected" >
<GridView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text='{Binding Key}' Foreground="#FF116C15" Margin="5" FontSize="28" FontFamily="Segoe UI Light" />
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.ContainerStyle>
<Style TargetType="GroupItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GroupItem">
<StackPanel Orientation="Vertical">
<ContentPresenter Content="{TemplateBinding Content}" />
<ItemsControl x:Name="ItemsControl" ItemsSource="{Binding GroupItems}" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid Orientation="Vertical" MaximumRowsOrColumns="5" />
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</GridView.GroupStyle>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid Orientation="Vertical" MaximumRowsOrColumns="1" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<Button Visibility="Collapsed"/>
</GridView>