惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
Arctic Wolf
T
Tor Project blog
G
GRAHAM CLULEY
I
InfoQ
博客园_首页
IT之家
IT之家
The Register - Security
The Register - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
U
Unit 42
PCI Perspectives
PCI Perspectives
量子位
P
Palo Alto Networks Blog
S
Securelist
T
Troy Hunt's Blog
博客园 - 【当耐特】
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
罗磊的独立博客
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Cloudbric
Cloudbric
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - *小小黄*

List<T>的Sort,Find,Exists等的使用(摘抄) JQuery常用代码1 使用Telerik控件时出现Failed to create designer 的解决方法 GridView 笔记 - *小小黄* - 博客园 Telerik Rad 笔记 一 Silverlight学习笔记四:如何通过自定义ComboBox实现SelectedValue Silverlight学习笔记三:如何自定义DataGrid的Header Silverlight学习笔记二:DataGrid 服务器端分页、排序的实现 Silverlight学习笔记一:DataGrid如何处理鼠标的滚轮事件 SQL2005快照 在ASP.NET中使用HTTP压缩 Web注册表单设计样式的研究(下) Web注册表单设计样式的研究(上) 禁用aspx页面的客户端缓存 DataGrid中没有数据时显示表头(转) 在 Windows Vista 上安裝 Reporting Services IIS7中访问Access数据库报错的解决方案 解决“无法删除文件:无法读源文件或磁盘” AjaxControlToolkit中的CalendarExtender被遮挡的解决方法
Silverlight学习笔记二(续)
*小小黄* · 2008-12-26 · via 博客园 - *小小黄*

上篇中在设置排序标志的时候,需要不停的去刷新,这样做肯定是不行的,所以必须要找到其它的方式。

看了一下关于自定义ColumnHeader的内容,在2.0的测试版本中,可以直接设置Column.Header为某个自定义的控件,但是在正式版中,这个功能被取消了,必须要通过Column.HeaderStyle来设置,动态设置Style还是比较费事的,暂时还没有做好。

所以想了个折中的办法,就是在Header上面手工加上"↑"和"↓"来标示排序的方向。

所要做的就是在MouseDown中修改一下Header.Content

代码如下:

 1 private void dgData_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 2         {
 3             var u = from element in VisualTreeHelper.FindElementsInHostCoordinates(e.GetPosition(null), dgData)
 4                     where element is DataGridColumnHeader
 5                     select element;
 6 
 7             if (u.Count() == 1)
 8             {
 9                 //鼠标点击的ColumnHeader
10                 DataGridColumnHeader header = (DataGridColumnHeader)u.Single();
11                 //要排序的字段
12                 string _newsort = header.Content.ToString();
13                 //清除名称中的↑和↓
14                 _newsort = removeSortStateFlag(_newsort);
15                 //判断排序方向
16                 if (_newsort == sortFiled)
17                     dir = dir == "desc" ? "asc" : "desc";
18                 else
19                 {
20                     //如果新的排序字段和当前的排序字段不一样,则要清楚当前排序字段的排序标志(↑↓)
21                     if (sortHeader!=null)
22                         sortHeader.Content = removeSortStateFlag(sortHeader.Content.ToString());
23                     dir = "asc";
24                 }
25                 sortFiled = _newsort;
26                 //加上排序标志
27                 header.Content = dir == "asc" ? _newsort + " ↑" : _newsort + " ↓";
28                 //设置新的排序字段为当前排序字段
29                 sortHeader = header;
30                 BindGrid();
31                 e.Handled = true;
32             }
33             else
34                 e.Handled = false;
35         }

完整的代码如下:

Code

最终效果: