title: Add column to listview that contains an image
body: <p>I want to add a row using data from a <code>ExpandoObject</code>, which is similar to a <code>Dictionary&lt;string, object&gt;</code>. The <code>string</code> is the header of the column and the <code>object</code>'s value is value of the column.
  Everytime, when I get new data I'm creating a new <code>GridView</code>, because the number of columns can be different. In the <code>List</code> myItems are all rows <code>Dictionary&lt;string, object&gt;</code>, that I want to show in my view.</p>
  
  <p>This is how I add the columns to my view:</p>
  
  <pre><code>            List&lt;Column&gt; columns = new List&lt;Column&gt;();
  
              myItemValues = (IDictionary&lt;string, object&gt;)myItems[0];
              // Key is the column, value is the value
              foreach (var pair in myItemValues)
              {
                  Column column = new Column();
                  column.Title = pair.Key;
                  column.SourceField = pair.Key;
                  columns.Add(column);
              }
              view.Columns.Clear();
              foreach (var column in columns)
              {
                  Binding binding = new Binding(column.SourceField);
                  if (column.SourceField == "Icon")
                  {
                      view.Columns.Add(new GridViewColumn
                      {
                          Header = column.Title,
                          DisplayMemberBinding = binding,
                          CellTemplate = new DataTemplate(typeof(Image))
                      });
                  }
                  else
                  {
                      view.Columns.Add(new GridViewColumn { Header = column.Title, DisplayMemberBinding = binding });
                  }
              }
  </code></pre>
  
  <p>Direct after this I try to add the rows:</p>
  
  <pre><code>            foreach (dynamic item in myItems)
              {
                  this.listView.Items.Add(item);
              }
  </code></pre>
  
  <p>I tryed to modify this <a href="https://stackoverflow.com/questions/33607040/c-sharp-add-new-row-in-listview">solution</a> for an other purpose. This solution works very well, if I only want to add values of the type <code>string</code>, but now I also want to display an <code>image</code> in the gridview, but if I add one to my gridview, it shows me just:</p>
  
  <blockquote>
    <p>"System.Windows.Controls.Image"</p>
  </blockquote>
  
  <p>Now I want to know, if I can modify my code so as I can display any type (or at least <code>images</code> and <code>strings</code>) in a gridview or do I have to use a completly new way and would be the way?</p>
  
  <p><strong>EDIT:</strong> In the previous approaches, it was said, that I need to create a new <code>DataTemplate</code> to show an image, but none of the solutions(<a href="https://stackoverflow.com/questions/248362/how-do-i-build-a-datatemplate-in-c-sharp-code">Solution 1</a>, <a href="https://stackoverflow.com/questions/5471405/create-datatemplate-in-code-behind">Solution 2</a>) I found is working for me.</p>