Denny Huber

Hi:

I'm writng a WPF app. My design is calling for separate behaviors for a single click vs. a double click in a list box.

If I have, say, 6 items in a list box selected and I single click on one item, I expect all items to be deselected and the single item selected. But if I have 6 items selected and I double click on one of the selected items, I want to grab all 6 selected items and copy them to another list.

The problem, of course, is that the first click of my double click is interpreted as a single click, a single item gets selected, and the double click then copies only one item.

Is there a simple way to deal with this I'm wishing for something like...

listBoxItem.IgnoreFirstClickWhenDoubleClicking = true;

My complicated, backup solution has me archiving the state before the first click and then reinstating the state on the double click, but this is a bit hacky for me.

Thanks,

Denny Huber



Re: Windows Presentation Foundation (WPF) Single click double click

Yi-Lun Luo - MSFT

Hello, I think you can handle only the PreviewMouseDoubleClick event, and check the ClickCount of the MouseButtonEventArgs. Please note you need the PreviewMouseDoubleClick since the default behavior of ListBox will handle MouseDown.






Re: Windows Presentation Foundation (WPF) Single click double click

Denny Huber

Thanks, Yi-Lun.

But it seems that the MouseDown event is getting fired before the PreviewMouseDoubleClick, so that by the time I see a double click, it's too late. The single item has already been selected.

Denny Huber