tags:

views:

15

answers:

1

I've got a WPF application with a ListBox in it. For this list box, I'd like to mimic the behaviour of the users control panel (since Windows Vista) -- that is: you single-click on a list item, and it's the same as double-clicking.

In Win32, I'd do this by turning on the LVS_EX_ONECLICKACTIVATE style.

In WPF, I've attempted to do this by handling the MouseLeftButtonUp event. Unfortunately, and this is odd, it sometimes picks up the wrong item.

For example, if you double-click the title bar (caption) to maximise the window, the second mouse-up occurs over the list box, and the event is raised. Similarly, if an item is partially in view, clicking on it scrolls it into view, but the mouse-up is raised against the item that's now in view, not the one clicked.

Now, again, if this was Win32 (before LVS_EX_ONECLICKACTIVATE), I'd get mouse capture on the mouse down, remember the item, and check that I had capture on mouse up.

But it's not Win32, it's WPF. How do I do single-click activation in a WPF list box?

A: 

I must admit I never stumbled across the LVS_EX_ONECLICKACTIVATE by now, but as I understood it handling "SelectionChanged" should do the trick.

Or is there a difference between double clicking on selection or activation on selection?

Marcus Riemer
That'd probably work, but I was also wondering if there was a way to get the keyboard accessibility that one-click-activate gets you in Win32.
Roger Lipscombe
Ah ok, the "SelectionChanged" event would probably also fire when the arrow keys are used for navigation, which is of course not acceptable.
Marcus Riemer