Type list of selected items in a wpf datagrid

前端 未结 1 891
闹比i
闹比i 2021-02-15 18:01

I send the selected items to a specific command when the selection changes (each item is a class X)

I get them as object how can I convert it to a list?

I tried:

1条回答
  •  执念已碎
    2021-02-15 18:16

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

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

    using System.Linq;
    
    IList list = obj as IList;
    IEnumerable SelectedItemsList = list.Cast();
    // or 
    List SelectedItemsList = list.Cast().ToList();
    

    0 讨论(0)
提交回复
热议问题