tags:

views:

45

answers:

2

I am working with MVVM and WPF.

VM contains -

  1. an Observable collection of Task (where Task is a class that has public properties TaskId, TaskTime and TaskDetails)
  2. CurrentTaskId

I can set background color of each rows by using one of the method below

  1. using ListView ItemContainerStyle Trigger OR
  2. using ListView ItemContainerStyleSelector

Now I want to set the background color of all the rows to LightBlue and the condition being Task.TaskId == VM.CurrentTaskId. How do I achive this?

I failed to implement it using the data trigger on the style because

<DataTrigger Binding="{Binding TaskId}" Value="1001">

is valid but using Binding for Value is not valid, something on the lines of

<DataTrigger Binding="{Binding TaskId}" Value="{Binding CurrentTaskId}">

I am able to implement the alternate row color and a specific color for certain rows using the StyleSelector but again how do I find the CurrentTaskId?

Also how would I implement the functionality to change background color everytime the CurrentTaskId changes?

A: 

Solved this using IMultiValueConverter and MultiBinding

byte
+1  A: 

You should try using multi-binding in your data trigger.

See this question for a similar solution - WPF DataTrigger - Setting ListBoxItem IsSelected

Matt Casto
Yes, that's exactly how I solved it. See my answer above. Thanks for the link +1
byte