【问题标题】:What is the Sorting property in WPF Tookit's DataGridControl?WPF Tookit 的 DataGridControl 中的 Sorting 属性是什么?
【发布时间】:2016-02-25 17:31:01
【问题描述】:

我正在尝试在 WPF Toolkit 上添加自定义列排序逻辑。在System.Windows.Control.DataGrid 中,这可以通过指定其Sorting 属性来完成

<DataGrid Name="DG1"
          AutoGenerateColumns="False"
          ItemsSource="{Binding}"
          Sorting="DataGrid_ThreeWaySorting">

及其背后的代码

    private void DataGrid_ThreeWaySorting(object sender, DataGridSortingEventArgs e)
    {
        //custom logic here
    }

如何在 WPF Toolkit 的 DataGridControl 上实现这一点?它没有Sorting 属性。

对绑定的项目进行排序比较慢,所以我希望在 UI 级别进行排序。

【问题讨论】:

    标签: c# wpf datagrid wpfdatagrid wpftoolkit


    【解决方案1】:

    您可以使用 CollectionViewSource 执行排序吗?

    <CollectionViewSource x:Key="Items" Source="{Binding}" >
       <CollectionViewSource.SortDescriptions>
           <scm:SortDescription PropertyName="Description" />
           <scm:SortDescription PropertyName="Id" />
       </CollectionViewSource.SortDescriptions>
    </CollectionViewSource>
    

    绑定到资源:

    <DataGridControl Name="DG1"
              ItemsSource="{Binding Source={StaticResource Items}}">
    

    【讨论】:

    • 如何使用 CollectionViewSource 进行三向排序? (升序、降序、无排序)
    • 为每个要排序的属性添加排序说明并指定排序方向
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-20
    • 2013-10-26
    相关资源
    最近更新 更多