ListView的组样式

时间:2013-11-12 16:33:27

标签: wpf listview

我的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>

现在当我还没有添加任何分组描述时,一切正常,即我的列表视图在一列中显示4个项目(由控件的大小决定),并且一旦另外一个项目到来,它就会显示在第二列中这样:

4 4 4
4 4 4
4 4
4 4

但是当我添加一个组desciption时,特定组中的所有项目都垂直显示为:

Group1 Group2
4 4
4 4
4 4
4 4
4 4
4 4

我希望每个组中的所有项目也遵循前面描述的完全相同的行为。

0 个答案:

没有答案