How to distinguish System.Windows.Controls.SelectedItemCollection?

I have a method:

private void DeletePuzzle(object param) { } 

param is System.Windows.Controls.SelectedItemCollection , which I got from the WPF ListView SelectedItems property.

Somehow I cannot distinguish it from an object for anything useful. I cannot create a System.Windows.Controls.SelectedItemCollection due to its level of protection, and param will not be dropped on IList , ICollection or IEnumerable .

How can I iterate over parameter items?

+42
wpf selecteditem
Dec 10 '09 at 0:43
source share
3 answers

That's right, figured it out. I kept trying to use it as

 IList<PuzzleViewModel> collection = (IList<PuzzleViewModel>)param; 

What told me that it cannot convert from SelectedItemCollection to IList ...

This is actually what you need to do.

 System.Collections.IList items = (System.Collections.IList)param; var collection = items.Cast<PuzzleViewModel>(); 
+76
Dec 10 '09 at 3:24
source share

from reflector: -

 [Category("Appearance"), Bindable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public IList SelectedItems { get { return base.SelectedItemsImpl; } } 

The selected ListView items are IList, id, to see the calling method.

+1
Dec 10 '09 at 0:51
source share

Check type: System.Collections.Generic.IList<(Of <(ListViewDataItem>)>)

-one
Dec 10 '09 at 0:46
source share



All Articles