gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 23:19:51 26 4
gpt4 key购买 nike

我在一个更大的项目中遇到了这个问题......所以我设置了一个“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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com