码迷,mamicode.com
首页 > 编程语言 > 详细

[wpf] collectionViewsource 排序 和分组

时间:2019-07-27 09:35:57      阅读:355      评论:0      收藏:0      [点我收藏+]

标签:collect   com   ace   resource   color   sort   排序   -name   rect   

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 排序 和分组

标签:collect   com   ace   resource   color   sort   排序   -name   rect   

原文地址:https://www.cnblogs.com/nocanstillbb/p/11253617.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!