wpf 如何投射 System.Windows.Controls.SelectedItemCollection?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1877949/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to cast a System.Windows.Controls.SelectedItemCollection?
提问by Matt Searles
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.
param 是一个System.Windows.Controls.SelectedItemCollection
,我从 WPFListView
的SelectedItems
属性中获得。
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
.
不知何故,我似乎无法将它从一个对象转换为任何有用的东西。System.Windows.Controls.SelectedItemCollection
由于其保护级别,我无法创建 a ,并且 param 不会强制转换为IList
,ICollection
或IEnumerable
。
How can I iterate through param's items?
如何遍历参数的项目?
回答by Matt Searles
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...
这告诉我它无法从 SelectedItemCollection 转换为 IList ...
This is in fact what you need to do.
这实际上是您需要做的。
System.Collections.IList items = (System.Collections.IList)param;
var collection = items.Cast<PuzzleViewModel>();
回答by Aran Mulholland
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.
ListView的Selected Items是一个IList,id喜欢看调用方法。
回答by pipelinecache
Check The Type:
System.Collections.Generic.IList<(Of <(ListViewDataItem>)>)
检查类型:
System.Collections.Generic.IList<(Of <(ListViewDataItem>)>)