开发者

How to cast a System.Windows.Controls.SelectedItemCollection?

开发者 https://www.devze.com 2022-12-14 02:44 出处:网络
I have a method: private void DeletePuzzle(object param) { } param is a System.Windows.Controls.SelectedItemCollection, that I got from a WPF ListView\'s SelectedItems开发者_运维知识库 property.

I have a method:

private void DeletePuzzle(object param) 
{
}

param is a System.Windows.Controls.SelectedItemCollection, that I got from a WPF ListView's 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 its protection level, and param won't cast to IList, ICollection or IEnumerable.

How can I iterate through param's items?


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>();


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消