Home Forums WPF controls Xceed DataGrid for WPF Binding DataCell property to Data Item property

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

    I’m trying to tie the background of each data cell with a property of the object they are associated with. Right now, I set the background of the cell as a side effect of the validation process, which works well but is more difficult to maintain as new ways to manipulate the data items are added to the project. I would prefer to do it using binding so I only have to write it once and then it will take care of itself.

    Here’s what I’m trying to do more specifically. My data item has several properties like “Title”,”FileName”,”Album”. It will also have either a list of modified properties, or several boolean values like “FileNameChanged”, “AlbumChanged”, etc. (whichever solution is easier). If I have a column of “Title”, I want each cell in that column to look at the “TitleChanged” property or in the list of changed properties of its particular data item, and based on that select which background it has. If I update the property through some other means (thus changing the boolean property or adding a property to the list), I want the background to automatically change. I assume this will require some sort of binding and a converter between the data item and the cell background, but I can’t figure out how best to put it together.

    Imported from legacy forums. Posted by Nisarg (had 1938 views)

    Xceed Support
    Post count: 5658

    The best way to achieve this would be to create a CellContentTemplate, which would be set on the required columns…

    In the DataTemplate (CellContentTemplate is of type DataTemplate), you would need to place DataTriggers, in which the Binding looks like this one:

    <DataTrigger Binding=”{Binding RelativeSource={RelativeSource AncestorType={x:Type xcdg:DataCell}}, Path=AlbumChanged}” Value=”True”>
    <Setter Property=”Background” Value=”HotPink”/>

    Imported from legacy forums. Posted by Marcus [Xceed] (had 2937 views)

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