简体   繁体   English

XAML端的C#WPF排序DataGrid

[英]C# WPF Sorting DataGrid on XAML side

I tried using the method documented in this thread: Pre-sorting a DataGrid in WPF 我尝试使用此线程中记录的方法: 在WPF中对DataGrid进行预排序

My issue however is that my datagrid's itemssource is not always the same...it will be bound to different observable collections during the execution of the program. 但是,我的问题是我的数据网格的itemssource并不总是相同的……它将在程序执行期间绑定到不同的可观察集合。 With that, how do I sort the data grid? 这样,如何对数据网格进行排序? Is there another way to do this? 还有另一种方法吗? on the display side.... 在显示面...

Thanks 谢谢

If you are using data binding to set the ItemsSource then just add an IValueConverter (via the Converter property) that converts it to a CollectionView when it's set. 如果使用数据绑定设置ItemsSource,则只需添加IValueConverter(通过Converter属性),即可在设置时将其转换为CollectionView。 If you are using code to set your ItemsSource then just follow their example. 如果您使用代码设置ItemsSource,则只需遵循其示例。

You won't be able to use XAML to populate the SortDescriptions on the CollectionView however, unless you write your own MarkupExtension or an attached property of some sort. 但是,除非您编写自己的MarkupExtension或某种附加属性,否则您将无法使用XAML填充CollectionView上的SortDescriptions。 These are somewhat advanced topics so please indicate if that is the kind of answer you are looking for. 这些是高级主题,因此请指出您是否正在寻找答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM