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


11 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)}

  5. David says:

    This works in Silverlight 3, just tried it out.
    Thanks! 🙂

  6. Zeeshan says:

    Hey shemesh, great work..
    i just tried it out … and its simply beautiful…
    thanks for sharing…
    keep up the good work man…!!

  7. Tomás says:

    Great Job, I used it in Silverlight 3, it worked great.

  8. vinodsardar says:

    Hey, It is workign for me. Thanks.

  9. Dan says:

    Tried this out in SL 4. Double-clicks seem to work only sometimes. Also if I click quickly repeatedly, double clicks are signalled. eg. if I tripple-click, I get two double-clicks- shouldn’t work like that, should it?

  10. Singroha says:

    Thx mam..
    It works for me..without silver light…. 🙂

  11. kode says:

    Great tip. Thanks!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: