【发布时间】:2009-07-23 00:26:30
【问题描述】:
我已将 WPF Datagrid 的 itemsource 设置为从 DAL 返回的对象列表。我还添加了一个包含按钮的额外列,xaml 在下面。
<toolkit:DataGridTemplateColumn MinWidth="100" Header="View">
<toolkit:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Click="Button_Click">View Details</Button>
</DataTemplate>
</toolkit:DataGridTemplateColumn.CellTemplate>
</toolkit:DataGridTemplateColumn>
这渲染得很好。但是在 Button_Click 方法上,有什么方法可以获取按钮所在的数据网格上的行吗?更具体地说,我的对象的一个属性是“Id”,我希望能够将它传递给事件处理程序中另一个表单的构造函数。
private void Button_Click(object sender, RoutedEventArgs e)
{
//I need to know which row this button is on so I can retrieve the "id"
}
也许我需要在我的 xaml 中添加一些额外的东西,或者我可能会绕道而行?任何帮助/建议表示赞赏。
【问题讨论】:
标签: c# wpf xaml datagrid datagridview