views:

420

answers:

1

I have a listbox that uses a UserControl as the item template. Inside the UserControl, I have an image (an X) that when clicked, sends out event to remove the UserControl(listitem) from the listbox.

Is there a way to prevent the listbox from selecting that item when a user clicks on the image but still allows listitem selection for everything else in the control?

A: 

Make sure you mark the event as handled when the user clicks the Image:

private void ImageClicked(object sender, RoutedEventArgs e)
{
    //send out event to remove UserControl

    //ensure the event doesn't bubble up further to the ListBoxItem
    e.Handled = true;
}

HTH, Kent

Kent Boogaart
I do , but I handle the "click" OnMouseButtonUp and apparently the Listbox handles selections OnMouseButtonDown. I've tried using the HitTest framework but thus far had no luck.
Bill
Handled the MouseLeftButtonDown event and fixed! I feel silly for asking now =)
Bill