title: Binding Style to DataGridTextColumns ElementStyle
body: <p>I have a datagrid with some objects. The objects have a name, a "type" property and a bunch of irrelevant properties.</p>
  
  <p>based on if the type is "MaterialType" or not i want to set a style for the cells textblock (bold &amp; intend 10px)</p>
  
  <p>I started out with a converter. => it gets the type and converts to a font-weight.</p>
  
  <pre><code>&lt;DataGridTextColumn.ElementStyle&gt;
      &lt;Style TargetType="TextBlock"&gt;
          &lt;Setter Property="FontWeight" Value="{Binding type, Converter={StaticResource ResourceKey=TypeToFontWeightConverter}}"/&gt;
          &lt;Setter Property="Padding" Value="10,0,0,0"/&gt;
      &lt;/Style&gt;
  &lt;/DataGridTextColumn.ElementStyle&gt;
  </code></pre>
  
  <p>It works.. but I only got to set the font-weight.</p>
  
  <p>I want an individual style.</p>
  
  <p>so I edited my converter into a TypeToStyle Converter</p>
  
  <pre><code>    class TypeToStyleConverter : IValueConverter
      {
          public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
          {
  
              Style style = new Style(typeof(TextBlock));
  
              if (value is Type &amp;&amp; value == typeof(MaterialType))
              {
                  style.Setters.Add(new Setter(TextBlock.FontWeightProperty, FontWeights.Bold));
                  style.Setters.Add(new Setter(TextBlock.PaddingProperty, new Thickness(0)));
              }
              else
              {
                  style.Setters.Add(new Setter(TextBlock.FontWeightProperty, FontWeights.Bold));
                  style.Setters.Add(new Setter(TextBlock.PaddingProperty, new Thickness(10,0,0,0)));
              }
              return style;
          }
  
          public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
          {
              throw new NotImplementedException();
          }
  
          #endregion
      }
  </code></pre>
  
  <p>Then I bind the converter.</p>
  
  <pre><code>&lt;DataGridTextColumn Binding="{Binding Name}"
                      Header="Name"
                      IsReadOnly="True"
                      Width="1*"
                      ElementStyle="{Binding type, Converter={StaticResource ResourceKey=TypeToStyleConverter}}"/&gt;
  </code></pre>
  
  <p>It all compiles fine. But no styles. The converter doesn't get triggered...</p>