如何投射 System.Windows.Controls.SelectedItemCollection? [英] How to cast a System.Windows.Controls.SelectedItemCollection?

查看:28
本文介绍了如何投射 System.Windows.Controls.SelectedItemCollection?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方法:

private void DeletePuzzle(object param) 
{
}

param 是一个 System.Windows.Controls.SelectedItemCollection,它是我从 WPF ListViewSelectedItems 属性中获得的.

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

不知何故,我似乎无法将它从一个对象转换为任何有用的东西.由于其保护级别,我无法创建 System.Windows.Controls.SelectedItemCollection,并且参数不会转换为 IList, ICollectionIEnumerable.

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.

如何遍历参数的项目?

推荐答案

好的,整理好了.我一直试图把它像

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

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

告诉我它无法从 SelectedItemCollection 转换为 IList ...

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

这篇关于如何投射 System.Windows.Controls.SelectedItemCollection?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆