WPF,ListView设置分组

CollectionViewSource 绑定的是从数据库取出的数据ListBind以DeptName为分组依据

ListBind}

正文

WPF,ListView设置分组_第1张图片

CollectionViewSource 绑定的是从数据库取出的数据ListBind
以DeptName为分组依据
    
        "Data"  Source="{Binding ListBind}">
            
                "DeptName"/>
            
        
    
 
  
分组字段也可以在后台中定义
CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(lvItemsCategory.ItemsSource);
    PropertyGroupDescription groupDescription = new PropertyGroupDescription("CategoryType")
"CategoryType"是要绑定的字段名
    view.GroupDescriptions.Add(groupDescription);

以DeptName为分组依据,扩展列头显示科室名称DeptName,
TextBlock绑定的数据为DeptName的Name,而不是Text="{Binding Path=DeptName}"

"list_Reg"  ItemsSource="{Binding Source={StaticResource Data}}" Style="{StaticResource ListViewStyle}">
                
                
                    
                        
                               

后来看到xml的分组

http://www.cnblogs.com/liuyazhou/archive/2009/09/10/1563886.html

WPF,ListView设置分组_第2张图片


        "OKData" XPath="/Info">
            
                "">
                    "12345" Name="Book1" Price="$32.05" Author="author1" Catalog="Business"/>
                    "23456" Name="Book2" Price="$32.05" Author="author2" Catalog="Language"/>
                    "34567" Name="Book3" Price="$32.05" Author="author3" Catalog="Business"/>
                    "67891" Name="Book4" Price="$32.05" Author="author4" Catalog="Business"/>
                    "78910" Name="Book5" Price="$32.05" Author="author5" Catalog="Language"/>
                    "89101" Name="Book6" Price="$32.05" Author="author6" Catalog="Business"/>
                    "91011" Name="Book7" Price="$32.05" Author="author7" Catalog="Business"/>
                    "10111" Name="Book8" Price="$32.05" Author="author8" Catalog="Business"/>                 
                
            
        
        <CollectionViewSource
            x:Key='src' Source="{Binding Source={StaticResource OKData},XPath=Item}">
            
            
                PropertyName="@Catalog"/>
            
        
    
    
    
        "listViewTask" ItemsSource='{Binding Source={StaticResource src}}'
                  BorderThickness="0" SelectionChanged="listViewTask_SelectionChanged" >
            
                
                    
                        
                    
                
            
            
            
                
                    "ID" DisplayMemberBinding="{Binding XPath=@ID}" Width="100"/>
                    "Name" DisplayMemberBinding="{Binding XPath=@Name}" Width="140"/>
                    "Price" DisplayMemberBinding="{Binding XPath=@Price}" Width="100"/>
                    "Author" DisplayMemberBinding="{Binding XPath=@Author}" Width="140"/>
                
            
        
原文链接: http://www.cto800.com/view/11971092829688260658.html 
  

你可能感兴趣的:(WPF)