Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You probably need to use custom columns, then you can pass the whole row into a converter while using the <code>ConverterParameter</code> to specify the current column, that way you can compare all the values:</p> <pre><code>&lt;DataGridTextColumn Binding="{Binding Column1}"&gt; &lt;DataGridTextColumn.ElementStyle&gt; &lt;Style TargetType="{x:Type TextBlock}"&gt; &lt;Setter Property="Background" Value="{Binding Converter={StaticResource ValueToBrushConverter}, ConverterParameter=1}"/&gt; &lt;/Style&gt; &lt;/DataGridTextColumn.ElementStyle&gt; &lt;/DataGridTextColumn&gt; &lt;DataGridTextColumn Binding="{Binding Column2}"&gt; &lt;DataGridTextColumn.ElementStyle&gt; &lt;Style TargetType="{x:Type TextBlock}"&gt; &lt;Setter Property="Background" Value="{Binding Converter={StaticResource ValueToBrushConverter}, ConverterParameter=2}"/&gt; &lt;/Style&gt; &lt;/DataGridTextColumn.ElementStyle&gt; &lt;/DataGridTextColumn&gt; &lt;!-- ... --&gt; </code></pre> <p>I do not quite that table of yours but you probably can figure out how to return the correct value in the converter on your own.</p> <hr> <p>Converter skeleton could be something like this:</p> <pre><code>public class ValueToBrushConverter : IValueConverter { /// &lt;summary&gt; /// 1st Indexer: Columns /// 2nd Indexer: Options /// &lt;/summary&gt; Brush[,] _brushMatrix = new Brush[5,4] { { Brushes.Gray, Brushes.Gray, Brushes.Gray, Brushes.Gray }, { Brushes.Gray, Brushes.Red, Brushes.Gray, Brushes.Blue }, { Brushes.Gray, Brushes.Red, Brushes.Gray, Brushes.Blue }, { Brushes.Gray, Brushes.Gray, Brushes.Red, Brushes.Blue }, { Brushes.Gray, Brushes.Gray, Brushes.Red, Brushes.Blue } }; public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { RowDataItem item = value as RowDataItem; int currentColumn = int.Parse(parameter as string); int currentRowOption; #region Internal logic here, e.g if (item.Col1 == "I" &amp;&amp; item.Col3 == "Love" &amp;&amp; item.Col2 == "Converters") { currentRowOption = 1; } //... #endregion return _brushMatrix[currentColumn, currentRowOption]; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotSupportedException(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload