예제 #1
0
 public static Microsoft.Windows.Controls.DataGridCell GetCell(Microsoft.Windows.Controls.DataGrid dataGrid, Microsoft.Windows.Controls.DataGridRow rowContainer, int column)
 {
     if (rowContainer != null)
     {
         DataGridCellsPresenter presenter = FindVisualChild <DataGridCellsPresenter>(rowContainer);
         if (presenter == null)
         {
             /* if the row has been virtualized away, call its ApplyTemplate() method
              * to build its visual tree in order for the DataGridCellsPresenter
              * and the DataGridCells to be created */
             rowContainer.ApplyTemplate();
             presenter = FindVisualChild <DataGridCellsPresenter>(rowContainer);
         }
         if (presenter != null)
         {
             Microsoft.Windows.Controls.DataGridCell cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as Microsoft.Windows.Controls.DataGridCell;
             if (cell == null)
             {
                 /* bring the column into view
                  * in case it has been virtualized away */
                 dataGrid.ScrollIntoView(rowContainer, dataGrid.Columns[column]);
                 cell = presenter.ItemContainerGenerator.ContainerFromIndex(column) as Microsoft.Windows.Controls.DataGridCell;
             }
             return(cell);
         }
     }
     return(null);
 }