好吧,我想通了,如何得到這個工作,我不得不調整被張貼在原來的問題是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」是聯繫在一起的變量我的數據網格。請注意,在我調用FindVisualChild時,我使用的是「DataGridDetailsPresenter」類而不是「ContentPresenter」(這是關鍵...它強制FindVisualChild方法遍歷所有內容演示者,直到我到達一個爲行細節)。
是的,在我的視圖模型,我可以在一個屬性用於數據網格的類。所以這是一個辦法。我只是想出瞭如何在類的代碼中做到這一點。我將把它作爲一個單獨的答案發布。感謝您的答覆! – BrianP 2010-08-10 21:11:27