Silverlight: double click a ListBox item

On my previous post i showed how you can attach a double-click event to any Silverlight object.
using this method i’ll show you how to attach a double click event to a ListBox item.

the problem here is that we don’t have any object that we can count on.
i edited the ListBoxItem template, the only change i’ve done is to add a transparent rectangle above all.
look for it inside the template – its name is “DummyRectForDoubleClick”.
then on the Loaded event of this rectangle i attach to it the double click event.

Demo is here
Source is here

4 Responses to “Silverlight: double click a ListBox item”

  1. mknopf Says:

    Thanks for the info and source code, your implementation is cleaner then most of the example’s I’ve seen.

  2. Alessandro Zambonin Says:

    Hi, i have tested this in Silverlight3, but does not work :(
    Have you tried ?

  3. shemesh Says:

    actually no, haven’t tried this on SL3.
    will check…

  4. memphis Says:

    This solution does not work on SL3. This error is shown:
    {System.IndexOutOfRangeException: Índice fuera de los límites de la matriz.
    en System.Windows.Controls.ItemContainerGenerator.RealizedItemBlock.ContainerAt(Int32 index)
    en System.Windows.Controls.ItemContainerGenerator.ContainerFromIndex(Int32 index)
    en System.Windows.Controls.ListBox.MakeToggleSelection(Int32 index)
    en System.Windows.Controls.ListBox.HandleItemSelection(ListBoxItem item, Boolean isMouseSelection)
    en System.Windows.Controls.ListBox.OnListBoxItemClicked(ListBoxItem item)
    en System.Windows.Controls.ListBoxItem.OnMouseLeftButtonDown(MouseButtonEventArgs e)
    en System.Windows.Controls.Control.OnMouseLeftButtonDown(Control ctrl, EventArgs e)
    en MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)}

Leave a Reply