Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
180
how to change row's background color based on one of my datasource's field
posted

I'm binding my xamDataGrid with entity class. All of my xamDataGrid's columns are UnboundFields.

One of my entity class' field is used as a reference for row's color change but this field is not shown/displayed in my xamDataGrid. How can I achieve this?

Presently, I'm doing like this:

In my xamDatagrid.FieldLayoutSettings, I defined a style to override datarecordcellareastyle, named MeetingTaskGridStyle:

<igDP:XamDataGrid.FieldLayoutSettings>

<igDP:FieldLayoutSettings AutoGenerateFields="False" AutoArrangeCells="Never" DataRecordCellAreaStyle="{StaticResource MeetingTaskGridStyle}"/>

</igDP:XamDataGrid.FieldLayoutSettings>

 

This MeetingTaskGridStyle is defined like this:

<Style x:Key="MeetingTaskGridStyle" TargetType="{x:Type igDP:DataRecordCellArea}">

<Style.Resources>

<LinearGradientBrush x:Key="MouseOverBrush" StartPoint="0.5, 0" EndPoint="0.5, 1">

<GradientStop Color="#22000000" Offset="0" />

<GradientStop Color="#44000000" Offset="0.4" />

<GradientStop Color="#55000000" Offset="0.6" />

<GradientStop Color="#33000000" Offset="0.9" />

<GradientStop Color="#22000000" Offset="1" />

</LinearGradientBrush>

<LinearGradientBrush x:Key="GreenBrush" StartPoint="0.5,0" EndPoint="0.5,1">

<GradientStop Offset="0.1" Color="#AA00CC00" />

<GradientStop Offset="0.8" Color="#55008800" />

</LinearGradientBrush>

<LinearGradientBrush x:Key="RedBrush" StartPoint="0.5,0" EndPoint="0.5,1">

<GradientStop Offset="0.1" Color="#AACC0000" />

<GradientStop Offset="0.8" Color="#55880000" />

</LinearGradientBrush>

<LinearGradientBrush x:Key="BlueBrush" StartPoint="0.5,0" EndPoint="0.5,1">

<GradientStop Offset="0.1" Color="#AA00AAAA" />

<GradientStop Offset="0.8" Color="#5500AAAA" />

</LinearGradientBrush>

<LinearGradientBrush x:Key="NoBrush" StartPoint="0.5,0" EndPoint="0.5,1">

<GradientStop Offset="0.1" Color="#AAAAAAAA" />

<GradientStop Offset="0.8" Color="#22AAAAAA" />

</LinearGradientBrush>

</Style.Resources>

<Setter Property="Padding" Value="0,4" />

<Setter Property="HorizontalContentAlignment" Value="Stretch" />

<Setter Property="Border.BorderThickness" Value="0,0,0,0.5" />

<Setter Property="Border.BorderBrush" Value="LightGray" />

<Style.Triggers>

<DataTrigger Binding="{Binding Path=TaskCategory}" Value="0">

<Setter Property="Background" Value="{StaticResource NoBrush}" />

</DataTrigger>

<DataTrigger Binding="{Binding Path=TaskCategory}" Value="2">

<Setter Property="Background" Value="{StaticResource NoBrush}" />

</DataTrigger>

<DataTrigger Binding="{Binding Path=TaskCategory}" Value="1">

<Setter Property="Background" Value="{StaticResource RedBrush}" />

</DataTrigger>

</Style.Triggers>

</Style>

But this is not working :( Any help? I really need support for this one. Thank you very much.

  • 180
    Verified Answer
    posted

    I have found a solution.

    Instead of this:

     <DataTrigger Binding="{Binding Path=TaskCategory}" Value="0">

    <Setter Property="Background" Value="{StaticResource NoBrush}" />

    </DataTrigger>

     

    It should be:

    <DataTrigger Binding="{Binding Path=DataItem.TaskCategory}" Value="0">

    <Setter Property="Background" Value="{StaticResource NoBrush}" />

    </DataTrigger>