Skip to content

Instantly share code, notes, and snippets.

@pinzolo
Created June 27, 2012 10:50
Show Gist options
  • Save pinzolo/3003270 to your computer and use it in GitHub Desktop.
Save pinzolo/3003270 to your computer and use it in GitHub Desktop.
[WPF]DataGrid のセルに存在するコントロールを取得する
using System.Windows.Controls.Primitives;
this.dataGrid.Items.ForEach<DataGridRowViewModel>(viewModel =>
{
var dataGridRow = this.dataGrid.ItemContainerGenerator.ContainerFromItem(viewModel) as DataGridRow;
var cellsPresenter = dataGridRow.FindVisualChild<DataGridCellsPresenter>();
var cell = cellsPresenter.ItemContainerGenerator.ContainerFromItem(viewModel) as DataGridCell;
var presenter = cell.Content as ContentPresenter;
var dbOutputValueTextBox = presenter.ContentTemplate.FindName("valueTextBox", presenter) as TextBox;
viewModel.Value = valueTextBox.Text;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment