Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/52.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试对数据网格进行排序时出错(XAML/C#)_C#_Datagrid - Fatal编程技术网

尝试对数据网格进行排序时出错(XAML/C#)

尝试对数据网格进行排序时出错(XAML/C#),c#,datagrid,C#,Datagrid,应该是一个简单的问题,但我找不到解决办法。我在c#中发现了这些错误: “System.Windows.Controls.DataGrid”不包含“Sort”的定义,并且找不到接受“System.Windows.Controls.DataGrid”类型的第一个参数的扩展方法“Sort”(是否缺少using指令或程序集引用?) 及 “System.Windows.Controls.DataGrid”不包含“Ascending”的定义,并且找不到接受“System.Windows.Controls.D

应该是一个简单的问题,但我找不到解决办法。我在c#中发现了这些错误:

“System.Windows.Controls.DataGrid”不包含“Sort”的定义,并且找不到接受“System.Windows.Controls.DataGrid”类型的第一个参数的扩展方法“Sort”(是否缺少using指令或程序集引用?)

“System.Windows.Controls.DataGrid”不包含“Ascending”的定义,并且找不到接受“System.Windows.Controls.DataGrid”类型的第一个参数的扩展方法“Ascending”(是否缺少using指令或程序集引用?)

这是我的密码:

XAML:

我做错了什么


提前感谢。

DataGrid
没有排序方法。关于如何在代码中对datagrid应用排序的博客文章和文章有很多。

您有任何可以为datagrid显示的xaml吗?抱歉,这是为了添加
谢谢,尽管我还有一个问题。。。如何创建ListSortDirection?我正在尝试
ListSortDirection=升序
但它表示
名称“升序”在当前上下文中不存在
它是
ListSortDirection direction=ListSortDirection.Ascending
<DataGrid Grid.Row="0" Grid.Column="0" Grid.RowSpan="5" Margin="0 0 25 0"  AutoGenerateColumns="True" Name="studentData" IsReadOnly="True" ItemsSource="{Binding}" />
private void sortByName_Click(object sender, RoutedEventArgs e)
    {
        studentDataGrid.ItemsSource = studentClass;
        studentDataGrid.Sort(studentDataGrid.Columns[0], studentDataGrid.Ascending);
    }