On a Silverlight ComboBox, the SelectionChanged event does not fire when you open the dropdown list, then click on the currently selected item. What's the best way to have an event/method trigger when this happens? (in addition to anything that would normally trigger SelectionChanged, i.e. they either click an unselected or selected item; but not when they just click off of the dropdown)
I currently have DataTemplates set up for the items in the list. I tried to attach to the MouseLeftButtonUp events of the elements in that, but there's a margin around the items, so it doesn't always register a click that closes the combobox and selects the item.
Asked
Active
Viewed 2,506 times
-1

Tim S.
- 55,448
- 7
- 96
- 122
2 Answers
1
Have you considered the "DropDownClosed" event?

BugFinder
- 17,474
- 4
- 36
- 51
-
Yes, I've considered that. The problem with it is that it also triggers when you open the dropdown and then click outside of the dropdown. The dropdown closes, so of course it fires, but the user didn't actually click on the currently-selected item, they made no selection, so I don't want to act as if they did. – Tim S. Jun 02 '11 at 20:30
-
Hmm, it does seem a messy thing, if the item is currently selected then I wouldnt select it again.. So thats exactly what Id do. You could have a boolean, selection_made=false, on drop down open, set it to yes, if mouse goes down, if on dropdownclosed, its been set then use the currently selected item.. but it is messy – BugFinder Jun 02 '11 at 20:37
-
Hm, yes a bit messy, but I'll try it tomorrow if no better suggestions come up. – Tim S. Jun 02 '11 at 22:29
-
I'm having trouble getting your suggestion to work. I've added a MouseLeftButtonDown handler to the ComboBox using .AddHandler so that it will take in handled events as well as unhandled ones, but it doesn't trigger when you click one of the items in the dropdown. A MouseLeftButtonDown in the tabitem's DataTemplate will trigger if they click in the portion of the dropdown that the element takes up, but not outside that. Any ideas? I'm going to try to modify the template of the ComboBox dropdown itself to include an event handler. I'll see how that goes... – Tim S. Jun 03 '11 at 14:13
0
I know it's been a long time since the last comment, but I'll post my solution in case someone out there is experiencing the same problem. The only way I managed to "re-select" the currently selected item was to modify the ComboBoxItemTemplate like this:
<Style TargetType="ComboBoxItem">
....
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBoxItem">
<Grid ... MouseLeftButtonDown="Grid_MouseLeftButtonDown">
...
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Now, in the Grid_MouseLeftButtonDown event I deselect the current item; the mouse click will then be handled as usual, selecting the element which is under the mouse cursor.

Sue Maurizio
- 662
- 7
- 17