两个 ItemsContorl 元素之间的鼠标事件
看看下面的代码。 BoxControl 具有 MouseLeftButtonDown/MouseLeftButtonUp 事件,当单击鼠标时这些事件可以正常工作 除了当鼠标单击下面的文本块时之外的框控件。我想要 BoxControl 的 MouseLeftButtonDown/MouseLeftButtonUp 事件 当鼠标单击下面的文本块时工作。感谢您的帮助!
Take a look at below code. BoxControl has MouseLeftButtonDown/MouseLeftButtonUp events and those work fine when the mouse is clicked on
the box control other than when the mouse is clicked on below text block. I want MouseLeftButtonDown/MouseLeftButtonUp events of BoxControl
to work when the mouse is clicked on below textblock. Appreciate your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它按预期工作。您的
BoxControl
是具有click
事件的控件,因此它是唯一监听这些事件的控件,而TextBlock
则不然。您可以执行以下两件事:
1) 在
BoxControl
中添加TextBlock
或
2) 添加
MouseLeftButtonDown
和MouseLeftButtonUp
当前TextBlock
上的 code> 事件,并获取这些 textblock_MouseClickHandlers 以委托给BoxControl
的事件处理程序It works as expected. Your
BoxControl
is the one which has theclick
events so that is the only control which is listening for these events, andTextBlock
isn't.There are two things you can do:
1) Add the
TextBlock
in yourBoxControl
OR
2) Add the
MouseLeftButtonDown
andMouseLeftButtonUp
events on your currentTextBlock
and get these textblock_MouseClickHandlers to delegate to the event handlers for theBoxControl
您应该挂钩 PreviewMouseLeftButtonDown 和 PreviewMouseLeftButtonUp 事件。如果您不希望它们进一步冒泡,请务必将它们标记为已处理。
You should hook into the PreviewMouseLeftButtonDown and PreviewMouseLeftButtonUp events instead. Make sure to mark them as handled if you don't want them to bubble up any further.