最佳答案
我已经将 WPF Datagrid 的项目源设置为从 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>
这样很好。但是在 按钮 _ 点击方法中,有没有什么办法可以获得按钮所在的 datagrid 行?更具体地说,我的对象的一个属性是“ 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"
}
也许我需要一些额外的东西在我的考试中,或者也许我正在以一种迂回的方式去做这件事?感谢你的帮助/建议。