Google 就像 Silverlight 中的 SearchBox
我在 Silverlight 中创建了一个类似 Google 的 SearchBox 控件。这意味着,当我在框中键入内容时,DropDownListBox 会出现在搜索框下方,显示与我迄今为止在搜索框中键入的文本匹配的所有项目(即自动完成功能),如下所示:
现在,我想为其添加一个功能:我想让 DropDownListBox 在用户点击外部后立即消失它或屏幕上的任何位置。我无法在其他控件中处理 MouseLeftButtonDown
(或任何此类 事件
)来完成此操作,因为用户可以单击任何位置,包括非 silverlight 区域。有人可以建议我应该做什么来实现这个目标吗?
所以我的问题基本上是:
如何知道用户是否刚刚单击并且单击事件发生在特定控件之外?
请注意,AutoCompleteBox
不符合我的目的。所以我不能使用它。
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:
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有一种感觉,使用 LostFocus事件可以解决您的问题。
I have a feeling that working with LostFocus event can solve your problem.
我想这个问题有点老了,但我只是偶然发现尝试做同样的事情并找到解决方案。这就是我所做的,
已经崩溃了。
部分,因此单击 SearchBox 或 DropDown 不会将其关闭。
我希望它可以帮助正在寻找类似问题的人。
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
is collapsed.
section, so clicking on SearchBox or DropDown wouldn't close it.
I hope it helps someone who is looking for the similar problem.