title: DataGridColumn with Header '*' already exists in the Columns collection of a DataGrid
body: <p>I have a WPF application with MVVM pattern. In one of my view, I have to bind an <code>ObservableCollection</code> to view. In that view, I have one <code>ListBox</code> and one <code>DataGrid</code> both bind to the same <code>ObservableCollection</code> but doing different things like events, style etc.. </p>
  
  <p>I need only one of these controls displayed at a time and what I did is created two user controls, one for <code>DataGrid</code> and other for <code>ListBox</code>. And I switched between them by placing a <code>ContentControl</code> on the main view(something similar to this <a href="http://rachel53461.wordpress.com/2011/05/28/switching-between-viewsusercontrols-using-mvvm/" rel="nofollow noreferrer">blog</a>. The default view is <code>DataGrid</code> and when click on a button the other view is displayed(i.e. <code>ListBox</code>). Up to this are working fine. </p>
  
  <p>One more thing to keep in mind that the Data Grid columns are generated dynamically by using the solution described in the following <a href="https://stackoverflow.com/questions/320089/how-do-i-bind-a-wpf-datagrid-to-a-variable-number-of-columns">link</a>. So when I go back to <code>DataGrid</code> view it's throwing an error while adding columns to Data Grid in <code>foreach</code> statement (pls refer the answer of the previous link) like </p>
  
  <blockquote>
    <p><em>"DataGridColumn with Header 'Ord' already exists in the Columns collection of a <code>DataGrid</code>. DataGrids cannot share columns and cannot contain duplicate column instances."</em></p>
  </blockquote>
  
  <p>But I'm sure that before adding columns to <code>DataGrid</code> its <code>Count</code> property is zero(dataGrid.Columns.Count()). So how the <code>DataGrid</code> header properties are persisted? Is there any way to clear the header values?.</p>
  
  <p>Please suggest... </p>