title: Datagrid column headers and values binding
body: <p>I'm having a problem with binding columns headers and values to data grid in MVVM PRISM.</p>
  
  <p>I'm having class SearchResult that has two properties : </p>
  
  <ul>
  <li>ColumnNames ---> those will apply to headers</li>
  <li><p>ColumnValues ---> those will apply to specific headers as their values.</p>
  
  <p>public class SearchResult
  {
      public List ColumnNames;</p>
  
  <pre><code>public List&lt;object&gt; ColumnValues;
  
  public string ColumnName { get; set; }
  public object ColumnValue { get; set; }
  
  public SearchResult()
  {
      this.ColumnNames = new List&lt;string&gt;();
      this.ColumnValues = new List&lt;object&gt;();
  }
  
  public void AddColumnAttributes(string columnName, object columnValue)
  {
      this.ColumnNames.Add(columnName);
      this.ColumnValues.Add(columnValue);
      this.ColumnName = columnName;
      this.ColumnValue = columnValue;
  }
  </code></pre>
  
  <p>}</p></li>
  </ul>
  
  <p>those properties are lists that are populated dynamically through C# code. </p>
  
  <p>And I need to bind them to columns headers and columns values in XAML.</p>
  
  <p>I've already created ObservableCollection Result which is the source of my gridview, but still is doesn't bind headers and values.</p>
  
  <pre><code>public ObservableCollection&lt;SearchResult&gt; Result
      {
          get { return this.searchResult; }
          set 
          { 
              this.searchResult = value;
              this.NotifyPropertyChanged("SearchResult");
          }
      }
  </code></pre>
  
  <p>And XAML:</p>
  
  <pre><code>&lt;DataGrid ItemsSource="{Binding SearchResult}" Width="350"&gt;
              &lt;DataGrid.Columns&gt;
                  &lt;DataGridTemplateColumn&gt;
                      &lt;DataGridTemplateColumn.Header&gt;
                          &lt;TextBlock Text="{Binding ColumnName, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"&gt;&lt;/TextBlock&gt;
                      &lt;/DataGridTemplateColumn.Header&gt;
                  &lt;/DataGridTemplateColumn&gt;
              &lt;/DataGrid.Columns&gt;
          &lt;/DataGrid&gt;
  </code></pre>
  
  <p>I'll appreciate any help with this!!!</p>