I having difficulties trying to change a cell background color based on an Unbound's field (with non-simple backend structure) underneath structure. Here is the sample "complex" structure:
public class TestTable
{
public int order { get; set; }
public TestMember t1 { get; set; }
public TestMember t2 { get; set; }
public TestMember t3 { get; set; }
}
public class TestMember
{
public TestMember(String i)
{
value = i;
}
public String value { get; set; }
}
and this is the XAML:
<igDP:XamDataGrid Name="xamDataGrid1">
<igDP:XamDataGrid.ViewSettings>
<igDP:GridViewSettings UseNestedPanels="False"/>
</igDP:XamDataGrid.ViewSettings>
<igDP:XamDataGrid.FieldSettings>
<igDP:FieldSettings AllowRecordFiltering="true" FilterLabelIconDropDownType="MultiSelectExcelStyle"
AllowEdit="False" AllowFixing="No" AllowSummaries="True"/>
</igDP:XamDataGrid.FieldSettings>
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings AutoGenerateFields="False" FilterUIType="LabelIcons"
HeaderPrefixAreaDisplayMode="FieldChooserButton" AllowClipboardOperations="All"
CopyFieldLabelsToClipboard="True" AddNewRecordLocation="OnTopFixed"
AllowAddNew="False" HighlightAlternateRecords="False" ExpansionIndicatorDisplayMode="Never"
/>
</igDP:XamDataGrid.FieldLayoutSettings>
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout Key="Layout0">
<igDP:FieldLayout.SortedFields>
<igDP:FieldSortDescription FieldName="order" Direction="Ascending"></igDP:FieldSortDescription>
</igDP:FieldLayout.SortedFields>
<igDP:FieldLayout.Fields>
<igDP:Field Name="order" Label="Ordinamento" AllowGroupBy="False" Visibility="Collapsed" FixedLocation="FixedToNearEdge"/>
<igDP:UnboundField BindingMode="TwoWay" BindingPath="t1.value" Name="value" AllowEdit="True" Label="Anno Recoil" AllowGroupBy="False" FixedLocation="FixedToNearEdge"/>
<igDP:UnboundField BindingMode="TwoWay" BindingPath="t2.value" Name="value" AllowEdit="True" Label="APC" FixedLocation="FixedToNearEdge"/>
<igDP:UnboundField BindingMode="TwoWay" BindingPath="t3.value" Name="value" Label="R1" AllowEdit="True" FixedLocation="FixedToNearEdge"/>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
What I'd like to get is a colored Grid the cells are black only when the root value is null, not when the leaf value is null.
The shown grid is the result of generating the second column rows a new TestMember with the value set to null. I'd like them to not be colored Black and treated differently. I've tired this converter:
<igDP:XamDataGrid.Resources>
<Style TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Background">
<Setter.Value>
<MultiBinding Converter="{StaticResource BackGroundConverter}">
<Binding RelativeSource="{RelativeSource Self}" Path="Value" />
<Binding RelativeSource="{RelativeSource Self}" Path="DataContext"/>
<Binding RelativeSource="{RelativeSource Self}" />
<Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Value" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
</igDP:XamDataGrid.Resources>
And what happens is that the CellValuePresenter passed to the multivalue converter has no field attached when the leaf value is null so I can't find an elegant way to retrieve in which column the value is null (either by root being null or leaf being null) and create a logic to color the cell in a proper way.
Thanks in advance, leave a comment if I didn't explain properly the issue.
Thanks again.
I resolved the issue by declaring a multibinding converter instead of the simple one and different styles like this:
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="keyX">
<Setter Property="Background">
<Setter.Value>
<MultiBinding Converter="{StaticResource BackGroundConverter}">
<Binding RelativeSource="{RelativeSource Self}" Path="Value" />
<Binding RelativeSource="{RelativeSource Self}" Path="DataContext"/>
<Binding Source="keyX"/>
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
and inside the multivalueconverter I do my checks based on the key passed. Obviously in the XamDataGrid you bind the style to the correspondent field, like this:
<igDP:UnboundField BindingMode="TwoWay" BindingPath="keyX.value" Name="value" AllowEdit="True" Label="Carica VN" FixedLocation="FixedToNearEdge">
<igDP:Field.Settings>
<igDP:FieldSettings CellValuePresenterStyle="{StaticResource keyX}" />
</igDP:Field.Settings>
</igDP:UnboundField>
and in the MultiValueConverter you make a switch-case based on the third binding:
switch (columnValue)
{
case "keyX":
single = row.getKeyXValue();
colorToApply = getStandardColor(single);
break;
...
That's all. Seems dirty to me, but since I've yet to find an elegant solution, this will work