I have a ListView whose ItemsSource is set to a collection property of my ViewModel. There is also a property on the ViewModel, say 'CurrentIndex', that changes as the code runs. As this changes I want ONLY the ListViewItem whose index in the ListView that matches 'CurrentIndex' to change, say its Background to change colour. As 'CurrentIndex' changes I want the previously referenced ListViewItem to be 'reset', i.e. its Background changes to it prior colour. Does anyone know how might I achieve this?
I thought of exploiting the SelectedIndex Property of the ListView but this doesn't work as the user can click on the ListView and change the selection thereby changing the background of the wrong item.
The ListViewItems are Templated via ItemTemplate in XAML.
Hope this makes sense.
Many thanks in advance for any help.
AlternationIndex
in a converter. An example use of the AlternationIndex can be found here – RachelCurrentIndex
toCurrentItem
which returnsItemCollection[CurrentIndex]
, and use anIMultiValueConverter
to see ifCurrentItem == Value
? Should be easy enough to pass both values to a Converter. I could probably find some kind of example if you needed it. – RachelIMultiValueConverter
. Thanks. – Cleve<Binding Path="DataContext.CurrentItem" RelativeSource="{RelativeSource AncestorType=ListBox}" />
) and the current data object (<Binding Path="." />
I think... could have syntax wrong), and your converter would just check if the two objects are equal. – Rachel