The ItemsSource of my Grid is a IEnumerable<SampleObject>.
The SampleObject consist of Guid id, String str1, String str2 and a ObservableCollection<SampleDynObject> dy.
The SampleDynObject consist of one strTest property.
After the creation of the xamWebGrid, I create TextColumns for the id, str1 and str2 data.
For the data from the SampleDynObject, I create UnboundColumns
UnboundColumn col = new UnboundColumn() { Key = Guid.NewGuid().ToString(), ValueConverter = new SampleConverter(), ValueConverterParameter = i };
The SampleConverter looks like this:
public class SampleConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { SampleObject so = value as SampleObject; int index = Int32.Parse(parameter.ToString()); //This is the index of the SampleObject's child collection if (so != null) { return so.dy[index].strTest; } return null; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } }
The question is: I tried to use the ContainingConditionalFormatRule, but it worked only on the TextColumns and not on the UnboundColumns.
My idea was to manually check the Rule by adding a second ValueConverter, but it seems to be only possible in the XAML-Markup and not by code.
So, how can I format the Background of the Cells.
I am curious why you are using an unbound column for this? I would suggest using a standard TextColumn instead and assigning the value converter to that.
Devin
Thank you for your answer.
I tried it, but then it required a key, but I don't know which key I shall use for binding it to the Collection objects.
I also tried to use a random key, but then the following exception occured:
The following key(s) do not correspond with the DataSource: "3d83f804-a1a8-4b77-b479-abe3494ff4cf". If you'd like to add additional columns, please use the UnboundColumn type.