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

前端 未结 3 1434
离开以前
离开以前 2020-12-13 05:24

I have a method:

private void DeletePuzzle(object param) 
{
}

param is a System.Windows.Controls.SelectedItemCollection, that

相关标签:
3条回答
  • 2020-12-13 06:05

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

    0 讨论(0)
  • 2020-12-13 06:06

    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.

    0 讨论(0)
  • 2020-12-13 06:16

    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>();
    
    0 讨论(0)
提交回复
热议问题