[wpf] collectionViewsource 排序 和分组

xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"

xmlns:swd = "clr-namespace:System.Windows.Data;assembly=PresentationFramework"
 

<CollectionViewSource x:Key="PeopleResource" Source="{Binding People}">

     < CollectionViewSource.SortDescriptions >
         < scm:SortDescription PropertyName = "Age" Direction = "Ascending" />
         < scm:SortDescription PropertyName = "LastName" Direction = "Ascending" />
     </ CollectionViewSource.SortDescriptions >
     < CollectionViewSource.GroupDescriptions >
         < swd:PropertyGroupDescription PropertyName = "Gender" />
     </ CollectionViewSource.GroupDescriptions >
</ CollectionViewSource >
 
< ListBox ItemsSource = "{Binding Source={StaticResource PeopleResource}}" >
     < ListBox.ItemTemplate >
         < DataTemplate >
             < StackPanel Margin = "10 0 10 5" >
                 < TextBlock Text = "{Binding FirstName}" />
                 < TextBlock FontWeight = "Bold" Text = "{Binding LastName}" />
                 < TextBlock Foreground = "Blue" Text = "{Binding Age}" />
             </ StackPanel >
         </ DataTemplate >
     </ ListBox.ItemTemplate >
     < ListBox.GroupStyle >
         < GroupStyle >
             < GroupStyle.HeaderTemplate >
                 < DataTemplate >
                     < Border BorderBrush = "Gray" BorderThickness = "0 0 0 4" >
                     < TextBlock FontSize = "14" FontWeight = "Bold"
                                Foreground = "Gray" Text = "{Binding Name}" />
                     </ Border >
                 </ DataTemplate >
             </ GroupStyle.HeaderTemplate >
         </ GroupStyle >
     </ ListBox.GroupStyle >
</ ListBox >

猜你喜欢

转载自www.cnblogs.com/nocanstillbb/p/11253617.html
今日推荐