title: Binding a cell object's property to a DataGridCell in WPF DataGrid
body: <p>Using the WPF DataGrid I have the need to change various display and related properties of a DataGridCell - such as Foreground, FontStyle, IsEnabled and so on  - based on the relevant value of the cell object property. </p>
  
  <p>Now this is easy to do in code, for example (using an Observable Collection of ObservableDictionaries):</p>
  
  <pre><code>  var b = new Binding("IsLocked") { Source = row[column], Converter = new BoolToFontStyleConverter() };
    cell.SetBinding(Control.FontStyleProperty, b);
  </code></pre>
  
  <p>and works fine, however I cannot see how to do this in XAML since I can find no way to set <strong>Path</strong> to a cell object's property.</p>
  
  <p>One XAML attempts is:</p>
  
  <pre><code>&lt;Setter Property="FontStyle"&gt;
      &lt;Setter.Value&gt;
          &lt;MultiBinding Converter="{StaticResource IsLockedToFontStyleConverter}" Mode="OneWay" UpdateSourceTrigger="PropertyChanged"&gt;
                &lt;Binding /&gt;
                &lt;Binding RelativeSource="{x:Static RelativeSource.Self}"/&gt;
          &lt;/MultiBinding&gt;
      &lt;/Setter.Value&gt;
  &lt;/Setter&gt;
  </code></pre>
  
  <p>but there is no binding to the <em>IsLocked</em> property</p>
  
  <pre><code>public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
  {
      var row = (RowViewModel) values[0];
      var cell = (DataGridCell) values[1];
      if (cell != null &amp;&amp; row != null)
      {
          var column = DataGridMethods.GetColumn(cell);
          return row[column].IsLocked ? "Italic" : "Normal";
      }
  
      return DependencyProperty.UnsetValue;
  }
  </code></pre>
  
  <p>Please note that a previous version returned <em>row[col].IsLocked</em> and set the FontStyle using a DataTrigger but a returned object is not databound. </p>
  
  <p>Note, of course, that the application does not know what the columns are at design time. </p>
  
  <p>Finally DataTable's are far too inefficient for my requirements but I would be interested to see how this is done with DataTables anyway, if there is such a solution for them, this might be useful elsewhere (although I prefer using collections).</p>
  
  <p>Surely this is a common issue and I am a WPF noobie trying to go all MVVM on my project, but this issue is holding me back with respect to using the WPF DataGrid.</p>