[wpf] collectionViewsource 排序 和分组
Posted nocanstillbb
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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
>
以上是关于[wpf] collectionViewsource 排序 和分组的主要内容,如果未能解决你的问题,请参考以下文章
wpf CollectionViewSource 分组后 如何控制 展开和折叠
在 WPF 中,您可以在没有代码的情况下过滤 CollectionViewSource 吗?