Hi...

I have a ListBox control where each entry consists of a template with a stackpanel and a textblock. The listbox is binded to an collection of class "Media". This object has a property "Highlighted". The template for each entry has a datatrigger on the Binding (Binding="{Binding Mode=OneWay, Path=Highlighted}" Value="True"). Then the Foreground Color should be set to "Green":

In the codebehind i registered an eventhandler: OnPreviewKeyDown(KeyEventArgs e). So if i hit the SPACE key the underlying "Media" objects "Highlighted" property will be set to "true".

My problem is now: The foreground color stays the same as before...nothing changed, not before i focused the next item with "Key Down" or "Key Up"...
How can I force the listbox to repaint everything? Is this the right way? Or is there a better method?

...

   
       
           
       

   

   
                   
           
      

   


...

...
protected override void OnPreviewKeyDown(KeyEventArgs e)
{
    Media me = ListBox.SelectedItem as Media;
   
    if (me.Highlighted == true)
        me.Highlighted = false;
    else
        me.Highlighted = true;
       
    e.Handled = true;
}
...