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
1770
Styling particular cell in particular rows based on flag
posted

I have a column in my grid. If the value is true I want to style particular cells on a particular row. This is what I have:

<Style x:Key="BoldTextStyle" TargetType="{x:Type igWPF:DataRecordCellArea}">
<Setter Property="FontWeight" Value="Bold" />
</Style>

private void DataGrid_OnInitializeRecord(object sender, InitializeRecordEventArgs e)
{
var dataRecord = e.Record as DataRecord;

if ((bool)dataRecord.Cells["TotalsFlag"].Value)
{
dataRecord.Cells["Column A"].EditorStyle = Resources["BoldTextStyle"] as Style;

dataRecord.Cells["Column D"].EditorStyle = Resources["BoldTextStyle"] as Style;
}
}

This of course throws and error since DataRecordCellArea is not derived from ValueEditor. How can I accomplish this?

Parents
No Data
Reply
  • 34810
    Verified Answer
    Offline posted

    Hello KrisVice,

    Thank you for your post.

    To achieve your requirement, I wouldn't recommend a style for DataRecordCellArea, as that represents a full-row area, but rather a single style for CellValuePresenter with nothing in the code-behind.

    For each cell in the XamDataGrid, there is a CellValuePresenter. The CellValuePresenter's data context is that of the data record that it sits in, and from that data record, you can obtain the data item and the properties on it. With this in mind, my recommendation to you would be a style with a single DataTrigger that binds to the property that your "TotalsFlag" cell represents. You could do this by using the following binding in your data trigger: {Binding DataItem.Flag}. Then, by giving this CellValuePresenter style a key, you can manually generate your fields and place your style on the CellValuePresenterStyle property of your fields via a StaticResource.

    I have attached a sample project to demonstrate the above. I hope this helps you.

    Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer
    Infragistics Inc.
    www.infragistics.com/support

    XDGCellStylingOnFlagCase.zip
Children
No Data