title: How generate custom columns for FrameworkElementFactory(typeof(Datagrid))?
body: <p>I have DataGrid which must have childGrid in RowDetails but i dont know how to create columns for child grid.<br>
  At the moment i have child grid with Autogenerated columns that i dont need:  </p>
  
  <pre><code>private static bool CopyWork(TextBox textBox)
  {
      try
      {
          var match = Regex.Match(textBox.Text, @"^коп раб");
          if (match.Success)
          {
              var copyWorkWindow = new Window()
              {
                  Topmost = true,
                  WindowStartupLocation = WindowStartupLocation.CenterScreen,
                  Title = "Копирование документов",
                  SizeToContent = SizeToContent.WidthAndHeight
              };
              var documents = new ObservableCollection&lt;CopyWorkDocument&gt;();
              var dataGrid = new DataGrid()
              {
                  ItemsSource = documents,
                  AutoGenerateColumns = false
              };
  
              var generateColumn = new Func&lt;string, string, object[], FrameworkElementFactory&gt;((header, bindingItem, items) =&gt;
              {
                  var column = new FrameworkElementFactory(typeof(DataGridTemplateColumn));
                  column.SetValue(DataGridTemplateColumn.HeaderProperty, header);
  
                  var binding1 = new Binding(bindingItem)
                  {
                      Mode = BindingMode.TwoWay
                  };
  
                  var elementTextBlock = new FrameworkElementFactory(typeof(TextBlock));
                  elementTextBlock.SetValue(TextBlock.TextProperty, binding1);
                  var cellTemplate = new DataTemplate
                  {
                      VisualTree = elementTextBlock
                  };
                  column.SetValue(DataGridTemplateColumn.CellTemplateProperty, cellTemplate);
  
                  if (items != null)
                  {
                      var elementComboBox = new FrameworkElementFactory(typeof(ComboBox));
                      elementComboBox.SetValue(ComboBox.BackgroundProperty, Brushes.White);
                      elementComboBox.SetValue(ComboBox.ItemsSourceProperty, items);
                      elementComboBox.SetValue(ComboBox.SelectedItemProperty, binding1);
                      var cellEditingTemplate = new DataTemplate
                      {
                          VisualTree = elementComboBox
                      };
                      column.SetValue(DataGridTemplateColumn.CellEditingTemplateProperty, cellEditingTemplate);
                  }
  
                  return column;
              });
              dataGrid.Columns.Add(new DataGridTextColumn() { Header = "Название документа", Binding = new Binding("Name") });
              dataGrid.Columns.Add(new DataGridTextColumn() { Header = "Количество копий", Binding = new Binding("Documentcount") });
  
              var rowDetailsTemplate = new DataTemplate();
              var pagesGrid = new FrameworkElementFactory(typeof(DataGrid));
              //pagesGrid.SetValue(DataGrid.AutoGenerateColumnsProperty, false);
              pagesGrid.SetValue(DataGrid.ItemsSourceProperty, new Binding("Pages"));
              rowDetailsTemplate.VisualTree = pagesGrid;
              dataGrid.RowDetailsTemplate = rowDetailsTemplate;
  
              copyWorkWindow.Content = dataGrid;
              copyWorkWindow.ShowDialog();
              var sB = new StringBuilder();
              foreach (var document in documents)
              {
                  sB.Append(document).Append(Environment.NewLine);
              }
              if (sB.Length &gt; 0)
              {
                  textBox.Text = sB.ToString();
              }
          }
          return match.Success;
      }
      catch (Exception ex)
      {
          ex.LogAndShow();
          return false;
      }
  }  
  </code></pre>
  
  <p>There is columnGenerator below.<br>
  Object class:  </p>
  
  <pre><code>private class CopyWorkDocument
  {
      public string Name { get; set; }
      public int Documentcount { get; set; } = 1;
      public List&lt;CopyPage&gt; Pages { get; set; } = new List&lt;CopyPage&gt; { new CopyPage() };
  
      public override string ToString()
      {
          var sB = new StringBuilder().Append(Name);
          foreach (var page in Pages)
          {
              sB.Append(Environment.NewLine).Append(Documentcount).Append("шт (").Append(page).Append(")");
          }
          return sB.ToString();
      }
  
      public class CopyPage
      {
          public int Pagecount { get; set; } = 1;
          public string Pageformat { get; set; } = "A4";
          public string Worktype { get; set; } = "печать";
          public string Printtype { get; set; } = "односторонняя";
          public bool IsColored { get; set; } = false;
  
          public static string[] Worktypes { get =&gt; new string[] { "печать", "копирование", "сканирование", "брошюровка", "твердый переплет" }; }
          public static string[] Printtypes { get =&gt; new string[] { "односторонняя", "двусторонняя" }; }
          public static string[] Formats { get =&gt; new string[] { "A4", "A3", "A2", "A1" }; }
  
          public override string ToString()
          {
              var sB = new StringBuilder().Append(Pagecount).Append(" ").Append(Pageformat);
              if (IsColored)
              {
                  sB.Append(" цвет");
              }
              return sB.ToString();
          }
      }
  }  
  </code></pre>
  
  <p>Example for colum generator:  </p>
  
  <pre><code>DataGrid.Columns.Add(generateColumn("ColumnName", "ColumnBinding", "ColumnItemsHelper"[]));
  </code></pre>
  
  <p>First i did this generator for DataGrid (Conrol), but then i rework it for FrameworkElementFactory (This useless details added because of StackOverflow codelimitation post)</p>