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. MySQL的几种登陆方式

    MySQL的几种登陆方式 登录方式一:    [root@001 tmp]# mysql -h 127.0.0.1 -u root -p 这是最标准的登录方式,意指通过tTCP/IP协议进行连接,因为 ...

  2. 安卓ADT离线安装

    http://jingyan.baidu.com/article/3aed632e66858770108091bf.html

  3. jquery实现重置

    $('#reset').click(function(){ $('#info_frm')[0].reset(); });

  4. php字符串中 转义字符 “ ’‘ ” ’ “” ‘ " \’ ' ' \‘ " " \" '' \ " " 使用

    <?php echo $str_string1='甲问:"你在哪里学的PHP?"'; echo "<br />"; echo $str_str ...

  5. Java泛型【转】

    一. 泛型概念的提出(为什么需要泛型)? 首先,我们看下下面这段简短的代码: public class GenericTest { public static void main(String[] a ...

  6. restlet验证

    1 restlet有无认证对比 无认证: 客户端发起请求 -----> 服务器路由 -----> 访问服务端资源 有认证: 客户端发起请求 -----> 认证 ----->服务 ...

  7. synchronized同步关键字

    参考:http://blog.csdn.net/luoweifu/article/details/46613015 synchronized是Java中的关键字,是一种同步锁.它修饰的对象有以下几种: ...

  8. DSP/BIOS使用之初窥门径——滴答时钟及烧写Flash

    操作平台和环境 DSP型号:TMS320C6713 仿真器:XDS510PLUS Flash型号:AM29LV800BT或AM29LV800BT都试过(一般接口一样,区别不大) RAM型号:MT48L ...

  9. (转)三层和mvc

    先说下两者出现的目的:三层是一种为了Project间解除耦合所提出来的简单的分层方式但MVC其实并不是基于Project的分层方式,而是一种解除展示模板与主要访问控制依赖的设计模式(其实全部都是基于U ...

  10. HTML5/CSS3鼠标滑过图片滤镜动画效果

    在线演示 本地下载