如果我们不涉及在 ViewModel 中接收此类信息从根本上来说是概念上错误的问题,那么这可以实现,但方式略有不同。
您对 DataGrid 可视化树存在误解。它是 ItemsControl 的继承者。因此,每一行旨在显示源集合的一个元素。单元格放置在一行中以表示该行的一个或另一个元素 - 通常是该元素的属性之一。这样的列实际上并不存在。这些只是细胞从中接收所需数据的容器。因此,该列不是单元格的祖先,更不用说其内容了。
但是单元格具有与其所在列进行通信的属性。你可以用它。
<DataTemplate x:Key="ButtonCellTemplate">
<Button Content="TestButton"
Command="{Binding TestCommand}"
CommandParameter="{Binding Column,
Mode=OneWay,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type DataGridCell}}}"/>
</DataTemplate>