title: WPF Dynamic DataGrid headers
body: <p>Since it is not possible to have <code>DataGrid</code> headers dynamically read some resource file, I used a method found here on SO to do so. It is working by having a <code>TextBlock</code> as a resource, which is dynamically reading some other <code>string</code> resource. Something like this:</p>
  
  <pre><code>&lt;DataGrid&gt;
      &lt;DataGrid.Columns&gt;
          &lt;DataGridTextColumn Header="{StaticResource dghName}"/&gt;
          &lt;DataGridTextColumn Header="{StaticResource dghAge}"/&gt;
      &lt;/DataGrid.Columns&gt;
  &lt;/DataGrid&gt;
  </code></pre>
  
  <p>and in the resources I would have this:</p>
  
  <pre><code>&lt;TextBlock x:Key="dghName" Text="{DynamicResource Name}"/&gt;
  &lt;TextBlock x:Key="dghAge" Text="{DynamicResource Age}"/&gt;
  
  &lt;sys:String x:Key="Name"&gt;Name&lt;/sys:String&gt;
  &lt;sys:String x:Key="Age"&gt;Age&lt;/sys:String&gt;
  </code></pre>
  
  <p>The string resources are within some separate file and when I just swap it for some other file with the same keys but with texts on some other language, the headers are changed.</p>
  
  <p>This was all working just fine, until there came a need for using the same resource on two places. I have the same <code>DataGrid</code> within two <code>TabItem</code>s. When I open the first one, the headers are shown normally, then I switch to the other tab, the headers are there as well. Now, when I change back to the first <code>TabItem</code>, the headers are empty. Same thing happens if I open the second tab first - when I switch to the first tab and then back to the second one, the headers are empty.</p>
  
  <p>It would have more sense to me, if there were no headers when I open the second tab, but they are show on both tabs for the first time, and then they are gone, when I open a tab (which was the first one to open) for a second time.</p>
  
  <p>The resources are within resource dictionaries, as <code>XAML</code> files.</p>