英文:
Get Item from DataGridCellInfo in WPF
问题
我应该如何从字段“Name”中获取值?
英文:
I have a DataGrid in WPF. The DataGridCellInfo contains Column
, IsValid
and Item
.
private void ProjectsDatagrid_SelectionChanged(object sender, MouseButtonEventArgs e) {
var selected = ProjectsDatagrid.SelectedCells[0];
}
I tried:
var foo = selected.Item.Name
var foo2 = selected.Item[Name]
How am I supposed to get the value from the field Name
?
答案1
得分: 0
将Item
转换为您的类型,例如:
var dataObject = selected.Item as YourClass;
if (dataObject != null)
{
string name = dataObject.Name;
//...
}
这里的YourClass
是一个具有Name
属性的自定义类。
英文:
Cast Item
to your type, e.g.:
var dataObject = selected.Item as YourClass;
if (dataObject != null)
{
string name = dataObject.Name;
//...
}
...where YourClass
is a custom class with a Name
property.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论