我有一个 WPF4 DataGrid
(WPF4 中包含的那个),其中包含“姓氏”、“名字”等列。当用户单击列标题(例如“姓氏”)时,所有内容都会按顺序排序根据我的文化设置正确的顺序,例如:
Anderson
Rockford
Ångström
我希望对“姓氏”列进行预先排序,所以我添加了
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="SurName" />
</CollectionViewSource.SortDescriptions>
就像 在 WPF 中预排序 DataGrid 问题。问题是,WPF 现在使用不同的排序顺序,其中“Å”的排序方式与“A”类似(我猜这是美国排序顺序):
Andersson
Ångström
Rockford
手动单击“姓氏”标题会重新对姓名进行排序,这次根据我的文化设置。
在对 DataGrid 进行预排序时,如何告诉 WPF 使用当前区域性设置?
I have a WPF4 DataGrid
(the one that's included with WPF4) with columns 'Surname', 'First Names' etc. When the user clicks a column header, for example 'Surname', everything gets sorted in the right order according to my culture settings, e.g:
Anderson
Rockford
Ångström
I want the 'Surname' column to be pre-sorted, so I've added
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="SurName" />
</CollectionViewSource.SortDescriptions>
just like in the answer to the Pre-sorting a DataGrid in WPF question. The problem is, that WPF now uses a different sort order where 'Å' is sorted like 'A' (I guess that's a US sort order):
Andersson
Ångström
Rockford
Manually clicking the 'Surname' header re-sorts the names, this time according to my culture settings.
How do I tell WPF to use the current culture setting when pre-sorting the DataGrid?
发布评论
评论(1)
您是否尝试过设置 CollectionViewSource 的 Culture 属性?类似于(干编码)根据您的评论进行编辑:
我不确定为什么 CollectionViewSource 默认情况下不会使用相同的区域性,但如果不是,这应该是为您修复它的属性。
另请参阅这篇文章,了解当目标是字符串时绑定似乎如何使用错误的区域性,也许它可以为您提供一些启示:http://www.nbdtech.com/Blog/archive/2009/02/22 /wpf-data-binding-cheat-sheet-update-the-internationalization-fix.aspx
或者这个问题:WPF XAML 绑定和 CurrentCulture 显示
Have you tried setting the CollectionViewSource's Culture property? Something like (drycoded) Edited per your comment:
I'm not sure why the CollectionViewSource wouldn't use the same culture by default, but if it's not this should be the property that fixes it for you.
See also this article on how binding seems to use the wrong culture when the target is a string, perhaps it can shed some light for you: http://www.nbdtech.com/Blog/archive/2009/02/22/wpf-data-binding-cheat-sheet-update-the-internationalization-fix.aspx
Or this question: WPF XAML Bindings and CurrentCulture Display