0

I am using the Xceed datagrid for WPF. Today I was trying to change the background of the whole row if one of its column "SA" has the some value or not null. I wrote the following piece of code in XAML with a converter function in code behind:

<xcdg:DataGridControl.Resources>
    <Style TargetType="{x:Type xcdg:DataRow}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource newConverter}, Path=Cells[SA].Content}" Value="True">
                <Setter Property="Background" Value="LightGreen" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
</xcdg:DataGridControl.Resources>

To my surprise, as soon as I load the grid for the first time, the data in the SA column is nowhere to be seen. However, once I scroll down a bit, till the point that row which is supposed to have data for the column is not visible, and then when I scroll up again to see that row, I can see the value in that column as well as the background changed.

What am I doing wrong?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kunal
  • 55
  • 5

1 Answers1

2

Use simple binding and avoid converter/template

<TextBlock Text="{Binding}"></TextBlock>

To fill color in your column use this or the following code:

<xcdg:Column Title="Unit Price" FieldName="UnitPrice" ReadOnly="True">
    <xcdg:Column.CellContentTemplate>
        <DataTemplate>
            <DockPanel LastChildFill="false" x:Name="UnitPrice">
                <TextBlock Text="{Binding}"></TextBlock>
                <Image x:Name="img" Width="16" Height="16" DockPanel.Dock="Right"
                       Margin="2,0,0,0" Visibility="Collapsed"
                       ToolTip="Unit Price is Undefined." VerticalAlignment="Center"
                       HorizontalAlignment="Left" />
            </DockPanel>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding}" Value="0.00">
                    <Setter TargetName="img" Property="Visibility"  Value="Visible" />
                    <Setter TargetName="UnitPrice" Property="Background"  Value="Pink" />

                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
    </xcdg:Column.CellContentTemplate>
</xcdg:Column>
Adi Lester
  • 24,731
  • 12
  • 95
  • 110
Dharmendra
  • 21
  • 2