Ссылка на FindVisualChild

Я нашел и изменил следующий код, чтобы экспортировать свою dataGrid в pdf документ, используя класс iTextSharp.

private void ExportToPdf(DataGrid grid)
    {
        PdfPTable table = new PdfPTable(grid.Columns.Count);
        using (Document doc = new Document(iTextSharp.text.PageSize.A4))
        {
            using (PdfWriter writer = PdfWriter.GetInstance(doc, new System.IO.FileStream("Test.pdf", FileMode.Create)))
            {
                doc.Open();
                for (int j = 0; j < grid.Columns.Count; j++)
                {
                    table.AddCell(new Phrase(grid.Columns[j].Header.ToString()));
                }
                table.HeaderRows = 1;
                IEnumerable itemsSource = grid.ItemsSource as IEnumerable;
                if (itemsSource != null)
                {
                    foreach (var item in itemsSource)
                    {
                        DataGridRow row = grid.ItemContainerGenerator.ContainerFromItem(item) as DataGridRow;
                        if (row != null)
                        {
                            DataGridCellsPresenter presenter = FindVisualChild<DataGridCellsPresenter>(row);
                            for (int i = 0; i < grid.Columns.Count; ++i)
                            {
                                DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(i);
                                TextBlock txt = cell.Content as TextBlock;
                                if (txt != null)
                                {
                                    table.AddCell(new Phrase(txt.Text));
                                }
                            }
                        }
                    }
                    doc.Add(table);
                    doc.Close();
                }
            }
        }
    } 

Проблема возникает в следующей строке:

DataGridCellsPresenter presenter = FindVisualChild<DataGridCellsPresenter>(row);

Visual Studio возвращает следующую ошибку «Имя« FindVisualChild »не существует в текущем контексте». Как мне добавить этот параметр?

Ответы на вопрос(2)

Ваш ответ на вопрос