silverlight4/5 修改源码实现 DataGrid 中文按拼音排序(第二版)
2013-10-25 17:24
183 查看
先前已经实现的方法需要修改多个dll:
排序:System.Windows.Data.dll
DataGrid:System.Windows.Controls.Data.dll
DataForm:System.Windows.Controls.Data.DataForm.Toolkit.dll
问题在于System.Windows.Data.dll经常被其它SDK引用,这样就需要修改强签名,今天有时间看了看排序的代码,问题出现在这里:
System.Windows.Data\PagedCollectionView\PagedCollectionView.cs
CultureInfo 用于本地化,如本地化的日期时间显示方式,当然也包含了排序方法。
提供有关特定区域性的信息。 这些信息包括区域性的名称、书写系统、使用的日历、用于数字和日期的格式以及排序字符串的顺序。
如果 culture 为空,则设置为 CultureInfo.InvariantCulture:
获取不依赖于区域性(固定)的 CultureInfo。
也就是说如果没有设置CultureInfo,就去掉区域设置。查看DataGird源码,哈哈,果然没有设置CultureInfo。
着手解决,CultureInfo.CurrentCulture:
获取表示当前线程使用的区域性的 CultureInfo 对象。
也就是如果 culture 为空,写为:
不就结了,不明白微软那样做出于什么考虑。
由于直接修改,排序:System.Windows.Data.dll,会引起强签名的麻烦,DataGrid看起来还没有其它SDK直接引用,从DataGrid入手,初始化排序类时设置CultureInfo就是了:
System.Windows.Controls.Data\DataGrid\DataGridDataConnection.cs
这就是我加入的设置CultureInfo的代码:
collectionView.Culture = collectionView.Culture ?? System.Globalization.CultureInfo.CurrentCulture;
如果collectionView.Culture为空,设置为当前区域而不是去除区域。
测试通过。
这是 Silverlight 4 的版本, Silverlight 5 没有提供源代码,需要从汇编修改,从汇编代码来看,public object GetDataItem(int index)方法,Silverlight 4/5实现的代码一致。修改方法同上篇文章,不再叙述。
已修改好的DLL下载:
DataGrid_SDK2
排序:System.Windows.Data.dll
DataGrid:System.Windows.Controls.Data.dll
DataForm:System.Windows.Controls.Data.DataForm.Toolkit.dll
问题在于System.Windows.Data.dll经常被其它SDK引用,这样就需要修改强签名,今天有时间看了看排序的代码,问题出现在这里:
System.Windows.Data\PagedCollectionView\PagedCollectionView.cs
public CultureSensitiveComparer(CultureInfo culture) : base() { this._culture = culture ?? CultureInfo.InvariantCulture; }
CultureInfo 用于本地化,如本地化的日期时间显示方式,当然也包含了排序方法。
提供有关特定区域性的信息。 这些信息包括区域性的名称、书写系统、使用的日历、用于数字和日期的格式以及排序字符串的顺序。
如果 culture 为空,则设置为 CultureInfo.InvariantCulture:
获取不依赖于区域性(固定)的 CultureInfo。
也就是说如果没有设置CultureInfo,就去掉区域设置。查看DataGird源码,哈哈,果然没有设置CultureInfo。
着手解决,CultureInfo.CurrentCulture:
获取表示当前线程使用的区域性的 CultureInfo 对象。
也就是如果 culture 为空,写为:
this._culture = culture ?? CultureInfo.CurrentCulture;
不就结了,不明白微软那样做出于什么考虑。
由于直接修改,排序:System.Windows.Data.dll,会引起强签名的麻烦,DataGrid看起来还没有其它SDK直接引用,从DataGrid入手,初始化排序类时设置CultureInfo就是了:
System.Windows.Controls.Data\DataGrid\DataGridDataConnection.cs
public object GetDataItem(int index) { Debug.Assert(index >= 0); IList list = this.List; if (list != null) { return (index < list.Count) ? list[index] : null; } PagedCollectionView collectionView = this.DataSource as PagedCollectionView; if (collectionView != null) { collectionView.Culture = collectionView.Culture ?? System.Globalization.CultureInfo.CurrentCulture; return (index < collectionView.Count) ? collectionView.GetItemAt(index) : null; }
这就是我加入的设置CultureInfo的代码:
collectionView.Culture = collectionView.Culture ?? System.Globalization.CultureInfo.CurrentCulture;
如果collectionView.Culture为空,设置为当前区域而不是去除区域。
测试通过。
这是 Silverlight 4 的版本, Silverlight 5 没有提供源代码,需要从汇编修改,从汇编代码来看,public object GetDataItem(int index)方法,Silverlight 4/5实现的代码一致。修改方法同上篇文章,不再叙述。
已修改好的DLL下载:
DataGrid_SDK2
相关文章推荐
- silverlight4/5 修改源码实现 DataGrid 中文按拼音排序
- localeCompare() 方法实现中文的拼音排序
- 含中文的List列表按中文拼音排序的实现方式 Java
- java 实现中文转化为拼音代码 汉字转化为拼音源码分享
- JS实现中文汉字按拼音排序的方法
- Mybatis Generator的model生成中文注释,支持oracle和mysql(通过修改源码的方式来实现)
- MySQL使用HQL语句实现按中文拼音排序
- Android 实现中文按拼音排序方法
- android下对于Cursor的中文拼音排序实现
- asp.net DataGrid 中文字符排序的实现代码
- Android实现中文按拼音排序方法
- js中实现中文按字母拼音排序
- Extjs Gird 支持中文拼音排序实现代码
- 基于jquery的使ListNav兼容中文首字拼音排序的实现代码
- 基于jquery的使ListNav兼容中文首字拼音排序的实现代码
- 用strcoll实现中文拼音排序
- 中文拼音排序(web前端实现)
- Hibernate 实现Oracle的中文汉字按照拼音排序
- [置顶] 修改mybatis-generator-1.3.2源码实现中文注释
- asp.net DataGrid 中文字符排序的实现代码