我已经将我的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>
Run Code Online (Sandbox Code Playgroud)
这很好.但是在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"
}
Run Code Online (Sandbox Code Playgroud)
也许我在我的xaml中需要额外的东西,或者我可能会以迂回的方式进行此操作?任何帮助/建议表示赞赏.