wpf的GridViewColumn的排序要用到ICollectionView   的SortDescriptions.

SortDescriptions数组里是 SortDescription, SortDescription有2个参数, 第一个为属性, 第二个为升序降序的选择。
难点主要是第一个, 什么为属性? 属性就是你单条记录所绑定的数据层, 然后在里面选择你想要通过数据层的哪个字段来排序。
示例:
  <DataTemplate x:Key="isVisibleShown">
            <TextBlock Visibility="{Binding Value.IsShowMe, Converter={StaticResource BooleanToVisibilityConverter}}">
                <TextBlock.Text>
                    <PriorityBinding>
                        <Binding Path="Value.Label" Converter="{StaticResource IsPropertyExistConverter}" IsAsync="True"/>
                        <Binding Path="Key" Converter="{StaticResource DebugConverter}" IsAsync="True"/>
                    </PriorityBinding>
                </TextBlock.Text>           
            </TextBlock>      
        </DataTemplate>
        <GridView x:Key="prGridView">
            <GridViewColumn HeaderTemplate="{StaticResource FieldCellTemplate}" CellTemplate="{StaticResource isVisibleShown}"/>
        </GridView>
这个prGridView中column应用了一个DataTemplate, 假如 GridView绑定一个字典Dictinory<string, Model>, 那每条就是一个KeyValuePair, DataTemplate里Text绑定了Model里面的Label, 
然后后台:
            ICollectionView view = CollectionViewSource.GetDefaultView(lsvConfig.ItemsSource);
            if (view.CanSort && view.SortDescriptions.Count <= 0)
            {
                view.SortDescriptions.Add(new SortDescription("Value.Label", ListSortDirection.Ascending));
                view.Refresh();
            }
指定按model里面的label来排序

WPF GridViewColumn Sort DataTemplate的更多相关文章

  1. WPF 动态创建 DataTemplate 及数据绑定

    WPF 动态创建 DataTemplate 及数据绑定 运行环境:Window7 64bit,.NetFramework4.61,C# 6.0: 编者:乌龙哈里 2017-02-22 参考: star ...

  2. WPF 获取 ListView DataTemplate 中控件值

    原文:WPF 获取 ListView DataTemplate 中控件值 版权声明:本文为博主原创文章,未经博主允许可以随意转载 https://blog.csdn.net/songqingwei19 ...

  3. WPF 中的DataTemplate 的嵌套

    <Window x:Class="WPF.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xa ...

  4. WPF : ControlTemplate和DataTemplate的区别

    ControlTemplate用于描述控件本身. 使用TemplateBinding来绑定控件自身的属性, 比如{TemplateBinding Background}DataTemplate用于描述 ...

  5. WPF中的DataTemplate

    <Window x:Class="DateTemplate应用.MainWindow" xmlns="http://schemas.microsoft.com/wi ...

  6. WPF ListBox的DataTemplate例子

    <ListBox Name="lbLogInfo"> <ListBox.ItemTemplate> <DataTemplate> <Gri ...

  7. WPF 后台重写 DataTemplate

    /// <summary> /// 配置类 /// </summary> public static class GridControlDeploy { /// <sum ...

  8. WPF后台生成datatemplate(TreeViewItem例子)

    public void loadCheckListDataTemplate(TreeViewItem tvi) { DataTemplate cdt = new DataTemplate(); Fra ...

  9. wpf 中的DataTemplate 绑定控件

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x ...

随机推荐

  1. 基于IAP和网口升级固件

    基于IAP和网口升级固件 一.      需求引入 现有嵌入式设备:基于ARM Cortex-M3处理器.带以太网通讯功能. 为减少设备维护成本节省宝贵的时间和金钱,须要设计网口升级固件功能. 本文描 ...

  2. linux下网卡绑定

    网卡绑定的作用:1.冗余,防止单点故障 2.防止传输瓶颈 1.交换机端口绑定: system-view link-aggregation group 1 mode manual 比如把端口1和2进行绑 ...

  3. android 自定义控件View在Activity中使用findByViewId得到结果为null

    转载:http://blog.csdn.net/xiabing082/article/details/48781489 1.  大家常常自定义view,,然后在xml 中添加该view 组件..如果在 ...

  4. Tensorlayer

    http://tensorlayer.readthedocs.io/en/latest/

  5. Python 进程、线程、协程、锁机制,你知多少?

    1.python的多线程到底有没有用? 2. 为什么在python里推荐使用多进程而不是多线程 3.进程.线程.协程.各种锁 4.Python多进程编程

  6. AWS:5.公有云编程

    主要内容 1.AWS接口 2.使用AWS命令行 3.使用python sdk编程 AWS接口 Console:web控制台 登录amazon后在"我的账户" -> AWS管理 ...

  7. git服务的安装和使用

    参考文章 http://www.centoscn.com/image-text/install/2014/0514/2972.html 1.搭建Git服务器yum安装Git服务器创建一个git用户,用 ...

  8. eclipse中 svn出现 E220000 解决办法

    这种情况,先试试修改svnserve.conf 中的 anon-access = none 然后重启eclipse   如果还是不行,还有可能是因为你修改了svn的配置链接后 跟他人的svn连接方式有 ...

  9. 关于String,StringBuffer与StringBuilder的区别

    String是字符串常量对象,对其进行改变时会相当影响效率,特别注意在循环中直接拼接字符串效率非常差. 如果你想改变字符串的值,更加推荐使用StringBuffer与StringBuilder两种可变 ...

  10. Discuz!支持发布视频帖子设定 + 修改后台文件

    最近想做一个地方性论坛,果断在阿里巴巴的phpwind论坛程序与腾讯旗下的discuz论坛程序中选择,虽然phpwind大气,后面还是 决定选择了discuz程序用来构建这个平台,经过一番安装后,发现 ...