WPF实现ListView大小图标和分组

XAML:
<ListView Grid.Row="3" Name="t_lvw_time" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Disabled" PreviewMouseDown="t_lvw_time_PreviewMouseMove" AllowDrop="True" DragOver="t_lvw_time_DragEnter" SelectionMode="Extended">

                <ListView.ItemsPanel>

                    <ItemsPanelTemplate>

                        <WrapPanel IsItemsHost="True"/>

                    </ItemsPanelTemplate>

                </ListView.ItemsPanel>

            <ListView.ItemTemplate>

                <DataTemplate>

                    <Grid Width="125" Height="70">

                        <Grid.RowDefinitions>

                            <RowDefinition/>

                            <RowDefinition/>

                        </Grid.RowDefinitions>

                        <Image Source="/ExtendSmartVTWPF;component/Images/go_home.png" HorizontalAlignment="Center" />

                        <TextBlock Text="{Binding Path=room_code}" TextWrapping="Wrap"  Grid.Row="1" HorizontalAlignment="Center"/>

                    </Grid>

                </DataTemplate>

            </ListView.ItemTemplate>

      



            <ListView.GroupStyle>

                    <GroupStyle>

                        <GroupStyle.ContainerStyle>

                            <Style TargetType="{x:Type GroupItem}">

                                <Setter Property="Template">

                                    <Setter.Value>

                                        <ControlTemplate TargetType="{x:Type GroupItem}">

                                            <Expander IsExpanded="True" BorderBrush="#B5B5B5" BorderThickness="0,0,0,1">

                                                <Expander.Header>

                                                    <DockPanel>

                                                        <TextBlock FontWeight="Bold" Text="{Binding Path=Name}" Margin="5,0,0,0" Width="150"     />

                                                    <TextBlock FontWeight="Bold" Text="数量:" Margin="0,0,0,0" Width="50"     />

                                                    <TextBlock FontWeight="Bold" Text="{Binding Path=ItemCount}" Margin="5,0,0,0" Width="150"     />

                                                </DockPanel>

                                                </Expander.Header>

                                                 <Expander.Content>

                                                    <Grid>

                                                        <Grid.RowDefinitions>

                                                            <RowDefinition ></RowDefinition>

                                                            <RowDefinition></RowDefinition>

                                                        </Grid.RowDefinitions>

                                                        <ItemsPresenter Grid.Row="0"/>

                                                        </Grid>

                                                </Expander.Content>

                                            </Expander>

                                        </ControlTemplate>

                                    </Setter.Value>

                                </Setter>

                            </Style>

                        </GroupStyle.ContainerStyle>

                    </GroupStyle>

                </ListView.GroupStyle>

            </ListView>

 后台:

            List<T> list=GetList();

            var sourceView = new ListCollectionView(list);

            var groupDesctripition = new PropertyGroupDescription("room_code");//按room_code分组,room_code为集合中的属性

            sourceView.GroupDescriptions.Add(groupDesctripition);

            listview1.ItemsSource = sourceView;

 

实例图片:

WPF实现ListView大小图标和分组

 

你可能感兴趣的:(ListView)