title: WPF ListView - how to add items programmatically?
body: <p>Even if I know it's not ideal - I need to programmatically populate a listView (for whatever reason).</p>
  
  <p>I am declaring my columns in the markup:</p>
  
  <pre><code>            &lt;ListView.View&gt;
                  &lt;GridView&gt;
                      &lt;GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}"/&gt;
                      &lt;GridViewColumn Header="Value" DisplayMemberBinding="{Binding Path=Value}"/&gt;
                  &lt;/GridView&gt;
              &lt;/ListView.View&gt;
  </code></pre>
  
  <p>I am adding the items like this in code (it's obviously in a loop):</p>
  
  <pre><code>            MyData data = getDataItem(index); //&lt; -- whatever
              ListViewItem item = new ListViewItem();
              item.DataContext = data;
              this.myListView.Items.Add(item);
  </code></pre>
  
  <p>Where MyData is defined as:</p>
  
  <pre><code>public class MyData
  {
      public string Name { get; set; }
      public string Value { get; set; }
  }
  </code></pre>
  
  <p>The items are being added (I can see the rows) but I don't see any content.</p>
  
  <p>Anyone any clue?</p>
  
  <p>Any help appreciated!</p>