I am using a CellValuePresenter to place a Grid and child elements of the Grid into each cell. When I handle the CellActivated event of the xamDataGrid, how can I access the WPF Grid element in that cell?
I looked at the CellActivatedEventArgs but didn't see anything in it that looked promising.
I would recommend getting the CellValuePresenter from the CellActivatedEventArgs and then using the VisualTreeHelper to find the child you want:
void grid_CellActivated(object sender, CellActivatedEventArgs e) { var cvp = CellValuePresenter.FromCell(e.Cell); int count = VisualTreeHelper.GetChildrenCount(cvp); for (int i = 0; i < count; i++) { var child = VisualTreeHelper.GetChild(cvp, i) as TextBlock; if (child != null) child.Text = "New Text"; } }
Just remember that the XamDataGrid uses record recycling by default and this may produce duplicate values while scrolling through the records.