views:

698

answers:

2

Basically, I have a list of colors and a defined datatemplate for listbox item:

<DataTemplate x:Key="colorItemDataTemplate">
    <Border x:Name="borderInner" BorderBrush="Black" BorderThickness="1" Background="{Binding Brush}" Width="11" Height="11" />
</DataTemplate>

Now, when I add a bunch of items into the listbox and then set the ListBox.ItemsSource property to my List, the listbox is filled correctly.

There is also a slider with its appropriate event handler. Within the event handler, Brush property of one of the items from the listbox is changed. Since the appearance of the item depends on the Brush Property, listbox should reflect the change.

I could reset the ItemsSource property, but then all items have their templates applied and with more than 200 items in the listbox, this is pretty slow.

So, is there any way to refresh the template for only one item from the listbox?

Thanx

+1  A: 

I'm not sure I follow. If you've bound the Background to the property, changing the property should automatically udpate the background of the ListBoxItem. If you're not seeing that, make sure you are either using a DependencyProperty or implementing INotifyPropertyChanged.

HTH, Kent

Kent Boogaart
thanks, this worked. I implemented INotifyPropertyChanged and it works as desired.
kornelijepetak
A: 

You could use a binding converter. In the converter class you could have some logic like

(pseudo-code)
if (ListBoxItem.IsSelected)
   return SpecialColorFromSlider
else
   return NormalListBoxColor
Jacob Adams