Home Forums WPF controls Xceed DataGrid for WPF Style Cell based on Data

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #23931 |

    I have a DataGridControl that has a DataGridCollectionView as its ItemSource. I would like to color the text in one field red based on its value or based on a property of the the class that provides the data to DataGridCollectionView, whichever is easier to explain. Currently I have the following which colors all the text in the row red

    <Style TargetType=”{x:Type xcdg:DataCell}”>
    <Style.Triggers>
    <DataTrigger Binding=”{Binding Path=Red}” Value=”True”>
    <Setter Property=”Foreground” Value=”Red” />
    </DataTrigger>
    </Style.Triggers>
    </Style>

    Please let me know if you know how I can make it only apply the red color to a particular cell (field).

    Imported from legacy forums. Posted by Michael (had 525 views)

    User (Old forums)
    Member
    Post count: 23064

    I think you need to create a CellContentTemplate and then add a style with the needed style trigger.

    In post 8524, the author sets the background to another column, in your case you need to set it based on the true/false value of another column, so you’ll need to add your style trigger above to the cell content template.

    Check Out this post: http://forums.xceed.com/forums/ShowPost.aspx?PostID=8524

    It contains this binding example:
    <code>
    <xcdg:Column FieldName=”column0″ Title=”ID” Width=”50″ DisplayMemberBinding=”{Binding XPath=column0}”>

    <xcdg:Column.CellContentTemplate>

    <DataTemplate>

    <TextBlock Text=”{Binding XPath=.,Mode=OneWay}” Background=”{Binding XPath=./@Background}”/>

    </DataTemplate>

    </xcdg:Column.CellContentTemplate>

    </xcdg:Column>
    </code>

    Imported from legacy forums. Posted by Richard (had 2918 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.