且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在wpf datagrid中键入所选项目的列表

更新时间:2021-09-27 06:41:47

SelectedItems 属性是非通用的 IList 。您不能简单地将其转换为通用的 IList< T>

The type of the SelectedItems property is the non-generic IList. You can't simply cast that to the generic IList<T>.

然而,您可以使用 LINQ 获取 IEnumerable< x> 列表< x>

You could however use LINQ to get an IEnumerable<x> or a List<x>.

using System.Linq;

IList list = obj as IList;
IEnumerable<x> SelectedItemsList = list.Cast<x>();
// or 
List<x> SelectedItemsList = list.Cast<x>().ToList();