My goal is to format the background color of a cell in a RadGridView in my WPF project to be that of the value in the underlying data. This data is dynamic however so I cannot use pre-defined templates
There are RGB values in my underlying table (albeit with spaces instead of commas so I use a converter to fix that) and in a test project where I had a single "colour" column and template, everything worked a treat:
<Window.Resources>
<local:StringToBrushConverter x:Key="lStringToBrushConverter"></local:StringToBrushConverter>
<DataTemplate x:Key="ColourCellTemplate">
<Border Name="lBorder" BorderThickness="3" Margin="1" CornerRadius="1" Width="100"
BorderBrush="{Binding Colour, Converter={StaticResource lStringToBrushConverter}}">
<TextBlock Background="{Binding ElementName=lBorder, Path=BorderBrush}" ></TextBlock>
</Border>
</DataTemplate>
</Window.Resources>
The problem is now how I can work with this template to be usable in a dynamic scenario. Essentially all I need to change is "Colour" in this part:
BorderBrush="{Binding Colour, Converter={StaticResource lStringToBrushConverter}}"
but I am not sure how that can be achieved in code-behind. I can use TryFindResource to get hold of the DataTemplate but the next step to change the Binding is where I'm stuck.
I have looked at this example from Telerik which works in different circumstances when the value is being compared against another value but it doesn't solve my problem.
Many thanks..