Silverlight 列表框触发 MouseRightButtonDown,但不触发 MouseLeftButtonDown
我在一个更大的项目中遇到了这个问题……所以我设置了一个“Testpoject”作为概念验证:
- 新的 Silverlight 应用程序
- 添加列表框
- 用几个复选框填充列表框
- 注册 listBox1_MouseLeftButtonDown
- 注册 listBox1_MouseRightButtonDown
您将看到,listBox1_MouseLeftButtonDown任何情况下都不会发生火灾...... 然而 listBox1_MouseRightButtonDown 触发得很好。
我尝试使用从 ListBox 派生的自定义类并覆盖,假设 ListBox 类中的某些内容设置了 e.Handled = false,但这也没有改变行为。
关于为什么会发生这种情况以及如何解决的任何想法?
(此问题还会阻止“父”控件接收单击事件...因此事件传递被破坏)
:编辑: 我用解决方法解决了我的问题...所以不再需要答案。只是如果有人想弄清楚为什么会发生这种情况;)
I have this problem in a bigger Project...... so I set up a 'Testpoject' as Proof of Concept:
- New Silverlight-Application
- Add Listbox
- Fill listbox with a few Checkboxes
- Register listBox1_MouseLeftButtonDown
- register listBox1_MouseRightButtonDown
You will see, that the listBox1_MouseLeftButtonDown won't fire under any circumstances....
listBox1_MouseRightButtonDown however fires just fine.
I tried using a custom Class deriving from ListBox and overriding, assuming something in the ListBox Class was setting e.Handled = false, but this did not change the behaviour, either.
Any Ideas on why this happens and how to fix?
(This problem also stops the 'parent'-control from receiving the Click-Event... so the Event-passing is broke)
:edit:
I fixed my problem with a workaround... so an answer is not required anymore. Just if somebody feels like figuring out why this is happening for the sake of it ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这似乎回答了您的问题。引用:
解决方案是在代码隐藏文件中添加事件处理程序。来自文章:
不过请参阅最后的警告。
This seems to answer your question. To quote:
The solution is to add the event handler in the code-behind file. From the article:
See the caveat at the end though.
这是设计使然。如果检查框架代码,您将看到 ListBoxItem 将 Handled 属性设置为 true。
我遇到了同样的问题,因此在 ListBoxItem.ItemTemplate 中,我在内容中添加了事件处理程序。
This is by design. If you check the framework code, you'll see that the ListBoxItem sets the Handled property to true.
I had this same exact problem, so in my ListBoxItem.ItemTemplate, I added the event handler in my content.