title: What does x:Key="{x:Type TextBox}" do?
body: <p>Everything is in the title:</p>
  <p>I've read more than once that setting a style like this:</p>
  <pre><code>&lt;Style TargetType=&quot;TextBox&quot;&gt;...&lt;/Style&gt;
  </code></pre>
  <p>was roughly equivalent to:</p>
  <pre><code>&lt;Style x:Key=&quot;{x:Type TextBox}&quot; TargetType=&quot;TextBox&quot;&gt;...&lt;/Style&gt;
  </code></pre>
  <p>(last time <a href="https://stackoverflow.com/questions/4853272/how-to-set-a-comboboxs-style-inside-a-wpf-datagrid/4853416#4853416">in a comment on another question</a>)</p>
  <p>both should apply the style to all textBoxes in the app (if they are put in the app's resources of course)</p>
  <p>but I tried both in my apps, and only the second one with the x:Key defined works.</p>
  <p>it seams quite logical for me, since the first one does not know where to be applied without any x:Key property set, but then what is the point of the first syntax?</p>
  <p><strong>Edit:</strong> example of code in my app that works fine:</p>
  <pre><code>&lt;Style x:Key=&quot;{x:Type ComboBoxItem}&quot; TargetType=&quot;{x:Type ComboBoxItem}&quot;&gt;
       &lt;Setter Property=&quot;HorizontalContentAlignment&quot; Value=&quot;Left&quot;/&gt;
       &lt;Setter Property=&quot;VerticalContentAlignment&quot; Value=&quot;Center&quot;/&gt;
  &lt;/Style&gt;
  </code></pre>
  <p>and code that doesn't:</p>
  <pre><code>&lt;Style TargetType=&quot;{x:Type ComboBoxItem}&quot;&gt;
       &lt;Setter Property=&quot;HorizontalContentAlignment&quot; Value=&quot;Left&quot;/&gt;
       &lt;Setter Property=&quot;VerticalContentAlignment&quot; Value=&quot;Center&quot;/&gt;
  &lt;/Style&gt;
  </code></pre>
  <p>I wrote this to get rid of the binding issues you get with comboBoxItems when you manipulate an existing ComboBox's itemsSource. And the first code works fine, but the second one does not.</p>
  <p>you can see this easily by setting the horizontalContentAlignment to Right</p>
  <p><strong>Edit 2:</strong> This code is simply put in a resource dictionary in my App.xaml. And replacing TargetType=&quot;{x:Type ComboBoxItem}&quot; with TargetType=&quot;ComboBoxItem&quot; makes no difference whatsoever</p>
  <p><strong>Edit 3:</strong> I just realized I might have forgotten to precise something important (sorry about that): though the styles are defined in xaml, I actually add the controls to the layout in my code behind as they are added dynamically. Might be where the trouble lies...</p>