As you may have seen, over the last few days I eventually found that to
format the DataGrid cell of a dynamically created column of byte[] I had to
apply a template to the column and I had to add a converter to the binding.
The template looks like this:
<Style x:Key="BinaryCellStyle" TargetType="{x:Type DataGridCell}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
In code I do this:
bindcol.CellStyle = (Style)Resources["BinaryCellStyle"];
Binding bind = new Binding("BinaryData");
bindcol.Binding = bind;
BinaryCellConverter converter = new BinaryCellConverter();
bind.Converter = converter;
This works and my converter puts a nice display in the column cells.
However, now I have to change the background colour of the cell depending
upon the byte[] value. I understand converters perfectly well, my problem is
figuring out where and how to plug a "byte[] to Background Colour" converter
into this tangle of code. How do I define the converter in the XAML and give
it the byte[] value for the colour calculation?
I tried fiddling with binding the Background property in the template, but
it crashes with everything I've tried. I've spent hours on this as usual, so
any pointers would be most welcome.
Greg