WPF实现ListView大小图标和分组_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > WPF实现ListView大小图标和分组

WPF实现ListView大小图标和分组

 2015/3/16 18:41:27  冣綮風  程序员俱乐部  我要评论(0)
  • 摘要:XAML:<ListViewGrid.Row="3"Name="t_lvw_time"HorizontalAlignment="Stretch"VerticalAlignment="Stretch"ScrollViewer.VerticalScrollBarVisibility="Auto"ScrollViewer
  • 标签:图标 实现 view list
XAML:
class="brush:csharp;gutter:true;"><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;

 

实例图片:

 

发表评论
用户名: 匿名