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:
The type of the SelectedItems
property is the non-generic IList. You can't simply cast that to the generic IList<T>.
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();