【发布时间】:2013-06-17 17:09:53
【问题描述】:
我有一个使用 DataTemplates 从 XML 文件填充的列表视图。在每一行上都会生成一个按钮。当您单击按钮时,我想对该行上的值做一些事情。到目前为止一切顺利。
我实际上正在使用此线程here 的第三个答案。
此解决方案的实际代码(带有神秘注释)是:
private void btnMoveFDAup(object sender, RoutedEventArgs e)
{
Button btn = ((Button)sender);
// btn.DataContext will get you to the row object where you can retrieve the ID
}
当我在调试器的监视窗口中查看 btn.DataContext 时,我看到了我需要的所有精彩数据:
问题是:我如何访问这些数据?我需要输入“名称”和几个布尔值;但我完全一无所知。
各种尝试
string name = btn.DataContext.Name;
只是抛出编译器错误。
提前致谢!
【问题讨论】:
标签: c# wpf listview datacontext