Skip to content

Change DataGrid row background based on current item.Status #17788

Answered by msneijders
sn4k3 asked this question in Q&A
Discussion options

You must be logged in to vote

This could do it:

<DataGrid ...>
    <DataGrid.RowTheme>
        <ControlTheme
            x:DataType="vm:YourItemType"
            BasedOn="{StaticResource {x:Type DataGridRow}}"
            TargetType="DataGridRow">
            <Setter Property="Background" Value="{Binding Status, Converter={StaticResource StatusToRowColorConverter}}" />
        </ControlTheme>
    </DataGrid.RowTheme>
</DataGrid>

Docs about making a custom converter here. (I made up StatusToRowColorConverter, you'd have to implement that yourself)

If your viewmodel object is observable and property Status raises a PropertyChanged the DataGridRow will respond to it.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@sn4k3
Comment options

@msneijders
Comment options

@sn4k3
Comment options

Answer selected by sn4k3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants