Sarfaraz Nawaz
Sarfaraz Nawaz

Reputation: 361472

Google like SearchBox in Silverlight

I've created a Google like SearchBox control in Silverlight. That means, as I type in the box, a DropDownListBox appears just below the SearchBox, showing all the items that match with the text I've typed in searchbox so far (i.e AutoComplete feature), exactly like this:

Google like SearchBox in Silverlight

Now, I want to add a functionality to it : I want to make the DropDownListBox to disappear, as soon as user clicks outside it, or anywhere on the screen. I cannot handle MouseLeftButtonDown (or any such event) in other controls, to accomplish this, because users can click anywhere, including non-silverlight region. Can anybody suggest me what should I do to achieve this?

So my question basically is:

How to know if user has just clicked and the click event occurred outside a particular control?

Please note that AutoCompleteBox doesn't serve my purpose. So I cannot use it.

Upvotes: 1

Views: 840

Answers (2)

Thr3e
Thr3e

Reputation: 368

I guess this question is a bit old, but i just stumble upon trying to do the same and finding a solution. This is what i did

  • Created a Border with All Margins -500, this will cover the full screen essentially.
  • On Click Behaviour of this Border, the dropdown section of SearchBox is collapsed.
  • Adjust z-Index of Border just below the SearchBox and DropDown section, so clicking on SearchBox or DropDown wouldn't close it.
  • Set Border Visibility Collapsed, and make it visible when DropDown is Visible.

I hope it helps someone who is looking for the similar problem.

Upvotes: 1

Rafal Spacjer
Rafal Spacjer

Reputation: 4918

I have a feeling that working with LostFocus event can solve your problem.

Upvotes: 3

Related Questions