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.
Now this is easy to do in code, for example (using an Observable Collection of ObservableDictionaries):
var b = new Binding("IsLocked") { Source = row[column], Converter = new BoolToFontStyleConverter() };
cell.SetBinding(Control.FontStyleProperty, b);
and works fine, however I cannot see how to do this in XAML since I can find no way to set Path to a cell object's property.
One XAML attempts is:
<Setter Property="FontStyle">
<Setter.Value>
<MultiBinding Converter="{StaticResource IsLockedToFontStyleConverter}" Mode="OneWay" UpdateSourceTrigger="PropertyChanged">
<Binding />
<Binding RelativeSource="{x:Static RelativeSource.Self}"/>
</MultiBinding>
</Setter.Value>
</Setter>
but there is no binding to the IsLocked property
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var row = (RowViewModel) values[0];
var cell = (DataGridCell) values[1];
if (cell != null && row != null)
{
var column = DataGridMethods.GetColumn(cell);
return row[column].IsLocked ? "Italic" : "Normal";
}
return DependencyProperty.UnsetValue;
}
Please note that a previous version returned row[col].IsLocked and set the FontStyle using a DataTrigger but a returned object is not databound.
Note, of course, that the application does not know what the columns are at design time.
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).
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.