好的,我想出了如何让这个工作我不得不调整在原始问题的 MSDN 文章中发布的代码......
DataGridRow row = (DataGridRow)(KeywordsGrid.ItemContainerGenerator.ContainerFromItem(KeywordsGrid.SelectedItem));
// Getting the ContentPresenter of the row details
DataGridDetailsPresenter presenter = FindVisualChild<DataGridDetailsPresenter>(row);
// Finding Remove button from the DataTemplate that is set on that ContentPresenter
DataTemplate template = presenter.ContentTemplate;
Button button = (Button)template.FindName("RemoveItemButton", presenter);
KeywordsGrid是绑定到我的变量DataGrid。请注意,在我对 的调用中FindVisualChild,我使用的是一个DataGridDetailsPresenter类而不是一个ContentPresenter(这是关键......它迫使该FindVisualChild方法一直遍历所有内容演示者,直到我找到行详细信息的那个)。