我的 CollectionViewSource 看起来像这样:
<CollectionViewSource x:Key="cvs" Source="{Binding PlayerNodeDTO}"/>
我绑定到上述 CVS 的 lIstview 如下所示:
<ListView Margin="0,30,0,0" ItemsSource="{Binding Source={StaticResource cvs}}" Style="{DynamicResource ListViewStyle1}" Height="578" ScrollViewer.VerticalScrollBarVisibility="Disabled" Background="Transparent" x:Name="liveGrid" SelectionChanged="PlayerNodeSelected">
<ListView.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Margin" Value="20,10,0,0"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border Name="Bd" BorderBrush="{x:Null}" BorderThickness="0" Padding="0">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Margin" Value="0,0,60,0"/>
</Style>
</GroupStyle.ContainerStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Grid Height="28">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal">
<TextBlock VerticalAlignment="Bottom" Margin="23,0,0,0" Foreground="White" FontWeight="Bold" FontSize="14" Text="{Binding Name}"/>
</StackPanel>
<Border Grid.Column="1" BorderBrush="White" BorderThickness="0,0,0,1"/>
</Grid>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<controls:Control1/>
<controls:Control1/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
现在,当我没有添加任何 groupdescription 时,一切正常,即,我的列表视图在一列中显示 4 个项目(由控件的大小决定),并且一旦多了一个项目,它就会显示在第二列中,如下所示:
4 4 4
4 4 4
4 4
4 4
但是当我添加一个组描述时,特定组中的所有项目都垂直显示为:
组 1 组 2
4 4
4 4
4 4
4 4
4 4
4 4
我希望每个组中的所有项目也遵循与前面描述的完全相同的行为。