简体   繁体   English

WPF-如何将所选项目从数据网格加载到ObservableCollection类型

[英]WPF - How to load selected item from a data grid to observablecollection type

ObservableStudent selected = datagrid.SelectedItem as ObservableStudent;

selected is null after this line is executed. 执行此行后, selectednull What is the reason behind this? 这背后的原因是什么?

you must instantiate the collection in the class constructor. 您必须在类构造函数中实例化集合。 and then it should work fine. 然后它应该可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM