tags:

views:

527

answers:

3

I have a method

private void DeletePuzzle(object param) {

}

param is a System.Windows.Controls.SelectedItemCollection, that I got from a WPF ListViews SelectedItems property.

Somehow, I can't seem to cast it from an object to anything useful. I can't create a System.Windows.Controls.SelectedItemCollection because of it's protection level, and param won't cast to IList, ICollection or IEnumerable.

How can I iterate through param's items???

Warm regards, Matt

A: 

check the Type: System.Collections.Generic.IList<(Of <(ListViewDataItem>)>)

pipelinecache
I think that's a Web Forms thing, not WPF.
itowlson
A: 

from reflector : -

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

Selected Items of ListView is an IList, id like to see the calling method.

Aran Mulholland
The calling method was from a RelayCommand (Josh Smiths version). The SelectedItemCollection was getting through ok, but one has to cast it to an IList, not an IList<T>, and then cast that.
Matt S
+1  A: 

Right, got it sorted. I kept trying to cast it like

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

Which told me it couldn't convert from SelectedItemCollection to IList...

This is in fact what you need to do.

System.Collections.IList items = (System.Collections.IList)param;
var collection = items.Cast<PuzzleViewModel>();

Thanks for the responses guys.

Warm regards, Matt

Matt S