0

I have a PopUp Window, which contains ListBox. In ListBox PreviewMouseUp event, I get the selected item from ListBox and close the PopUp. However, even the ScrollBar of the ListBox sends these PreviewMouseUp events, so I am not able to scroll the list without getting the PopUp closed..

How can I separate the click of an item in the list from a click of the ScrollBar?

2
  • For the user the most obvious way to confirm his choice will be to click button. As an alternative, you could use double-click event. Commented May 20, 2014 at 11:22
  • Finally I sorted this out myself - Adding ListBox inside a ScrollViewer did the trick. Commented May 20, 2014 at 11:30

3 Answers 3

1

Putting the ListBox inside a ScrollViewer works.

Sign up to request clarification or add additional context in comments.

Comments

0

You should use this event: SelectedIndexChanged on your listbox. This event is fired when you select a new item from your listbox.

5 Comments

Yes, but this also fires when keyboard is used to scroll through items, so it cannot be used
Whats the matter with using the keyboard instead of the mouse?
If you carefully read my question, I mention about closing the PopUp window when value is selected, so obviously I cannot use SelectedIndexChanged to detect mouseselection, because I need to close the Popup. User has these options: a) Select value by mouse b) Select with keyboard and press Enter or Space
@Jaska Sorry for miss reading but you could use this Clickme to check if mouse button is pressed. You could also use an else if to do something else if keyboard is used.
I already solved this by adding the ListBox inside a ScrollViewer, then the ScrollBar has it's own events and ListBox has it's own.
0

can you not use the

 PreviewMouseLeftButtonUp

Event? This shouldonly firewhen you release the left mouse button and not when you scroll with the mousewheel. Or maybe its even better to use the

SelectedIndexChanged 

Event of your ListBox to make sure you dont click the Mousebutton and notselecteing a ListBox Element with that click.

Edit:

Okay then why dont you handle the dbl click event or maybe better add a button and get the selected item of your ListBox when the button is clicked and do whatever you want with it.

1 Comment

I didn't mention about the wheel, but using the scrollbar with mouse pressed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.