Silverlight 列表框触发 MouseRightButtonDown,但不触发 MouseLeftButtonDown

标签 silverlight events silverlight-4.0 mouseclick-event

我在一个更大的项目中遇到了这个问题......所以我设置了一个“Testpoject”作为概念证明:

  • 新的 Silverlight 应用程序
  • 添加列表框
  • 用几个复选框填充列表框
  • 注册 listBox1_MouseLeftButtonDown
  • 注册 listBox1_MouseRightButtonDown

您会看到,listBox1_MouseLeftButtonDown 在任何情况下都不会触发.... 然而,listBox1_MouseRightButtonDown 触发得很好。

我尝试使用派生自 ListBox 的自定义类并覆盖,假设 ListBox 类中的某些内容设置为 e.Handled = false,但这也没有改变行为。

关于为什么会发生这种情况以及如何解决的任何想法?

(此问题还会阻止“父”控件接收点击事件...因此事件传递中断)

:编辑: 我用解决方法解决了我的问题......所以不再需要答案。只是如果有人想弄清楚为什么会发生这种情况;)

最佳答案

This似乎回答了你的问题。引用:

That's because ListBoxItem internally handles this event as well as the MouseLeftButtonDown event (halting the bubbling) to implement item selection.

解决方案是在代码隐藏文件中添加事件处理程序。来自文章:

Although setting the RoutedEventArgs parameter's Handled property to true in a routed event handler appears to stop the tunneling or bubbling, individual handlers further up or down the tree can opt to receive the events anyway! This can only be done from procedural code, using an overload of AddHandler that adds a Boolean handledEventsToo parameter.

请参阅最后的警告。

关于Silverlight 列表框触发 MouseRightButtonDown,但不触发 MouseLeftButtonDown,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2809402/

相关文章:

asp.net - Azure 媒体播放器 Silverlight 后备不起作用

silverlight - 如何使用 MVVM 在 Silverlight 4.0 中执行导航?

c# - 使用委托(delegate)和事件从另一个表单更新表单

Silverlight MVVM : where did my (object sender, RoutedEventArgs e) 去了吗?

asp.net - 使用 asp.net 网站优化加载 XAP 文件

c# - 如何在 Silverlight 中创建客户端帮助程序类?

javascript - VueJS 表单与输入事件

c# - 附加到工厂实例化的单例事件 - 什么是干净的方法?

validation - 如何在 ItemsControl 内的 TextBox 上使用 ValidatesOnDataErrors

silverlight - 是否可以在没有IIS的情况下使用Silverlight RiaServices?