Sandy
Sandy

Reputation: 6353

How to change the background color dynamically of the particular row of GridView in WPF?

I am add rows in grid view dynamically as listViewResult.Items.Add(new { Server = "test1", Value = "ABX", Availability = "Yes", Status = "No"}); At the same time i want to add the background color of the same row which i have added on the basis of Status Value. How can i achieve this?

Upvotes: 0

Views: 993

Answers (2)

Andrei Pana
Andrei Pana

Reputation: 4502

You could add a ListViewItem element directly:

ListViewItem lvi = new ListViewItem();
lvi.Background = ... color you want ... ;
lvi.Content = new {Server = "test1", .... };
listViewResult.Items.Add(lvi);

Binding the Background to the Status will only work if Status is a DependencyProperty. If it's just a report and Status doesn't changed, there's no need to create a Binding, just set a color based on the Status' value.

Upvotes: 2

David
David

Reputation: 6114

the best way to do this is to edit your ListViewItem's template and bind the Background property to the item's Status property using a converter to convert the status into a Brush/Color.

it's not as trivial as it may sound though...

Upvotes: 1

Related Questions