惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
罗磊的独立博客
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
云风的 BLOG
云风的 BLOG
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
A
About on SuperTechFans
WordPress大学
WordPress大学
B
Blog
Martin Fowler
Martin Fowler
Jina AI
Jina AI
I
InfoQ
P
Proofpoint News Feed
小众软件
小众软件
S
SegmentFault 最新的问题
V
V2EX
B
Blog RSS Feed
量子位
大猫的无限游戏
大猫的无限游戏
aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
MongoDB | Blog
MongoDB | Blog
美团技术团队

博客园 - 阿冠

git报错unable to read tree xxxxxx socket tcp 报错误码 103/10053 原因 NuGet 未能为 SSL/TLS 安全通道建立信任关系 NuGet 未能为 SSL/TLS 安全通道建立信任关系 Visual Studio Font Cache 字体缓存路径下的文件太大了 ControlTemplate 中 Bingding 附加属性时需要加入 Path WPF使用第三方的字体(TTF文件) Base class for cloning an object in C# 关闭Windows 系统当前连接的Wifi以及判断物理\虚拟网卡,有线\无线网卡 - 阿冠 - 博客园 WPF 竖排文字 WPF 将DLL嵌入EXE文件(安装包) WPF 程序自删除(自毁)|卸载程序删除 WPF listbox UI虚拟化 记一次纠结Macbook 重装OS X的系统 指定的元素已经是另一个元素的逻辑子元素。请先将其断开连接。(解决问题总结) foreach---集合已修改;可能无法执行枚举操作。 WPF_View中控件使用单例ViewModel 判断s2是否能够被通过s1做循环移位(rotate)得到的字符串是否包含 多列转1列 SqlServer 实现oracle10g的 wmsys.wm_concat()--for xml path('')
无法将类型为“System.Windows.Controls.SelectedItemCollecti...
阿冠 · 2015-08-10 · via 博客园 - 阿冠
在WPF中DataGrid 选择事件中获取SelectedItems
报错如下
无法将类型为“System.Windows.Controls.SelectedItemCollection”的对象强制转换为类型“System.Collections.Generic.IList`1[SomeModel]”。
应该如此使用

  System.Collections.IList items = (System.Collections.IList)this.dataGrid.SelectedItems;

  var collection = items.Cast<SomeModel>();

  var someModelList = collection.ToList(); 

-------------------------------------

Cast 方法

 //
        // 摘要: 
        //     将 System.Collections.IEnumerable 的元素转换为指定的类型。
        //
        // 参数: 
        //   source:
        //     包含要转换的元素的 System.Collections.IEnumerable。
        //
        // 类型参数: 
        //   TResult:
        //     source 中的元素要转换成的类型。
        //
        // 返回结果: 
        //     一个 System.Collections.Generic.IEnumerable<T>,包含已转换为指定类型的源序列的每个元素。
        //
        // 异常: 
        //   System.ArgumentNullException:
        //     source 为 null。
        //
        //   System.InvalidCastException:
        //     序列中的元素不能强制转换为 TResult 类型。
        public static IEnumerable<TResult> Cast<TResult>(this IEnumerable source);

View Code