快速使用滚动条时,WPF文本框的DoubleClick事件触发 [英] WPF TextBox DoubleClick Event Fires when using Scrollbars rapidly

查看:180
本文介绍了快速使用滚动条时,WPF文本框的DoubleClick事件触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF文本框,这样定义的:

I have a WPF TextBox, defined like this:

<TextBox Text="{Binding Path=/Comments}" 
    Margin="351,193.91,10,36" 
    x:Name="txtComments" 
    IsReadOnly="True" 
    VerticalScrollBarVisibility="Auto" 
    LostFocus="txtComments_LostFocus" 
    MouseDoubleClick="txtComments_MouseDoubleClick" 
    AcceptsReturn="True" />

这工作完全如我所愿;然而,当VerticalScrollBars是可见的,如果你快速点击滚动条txtComments_MouseDoubleClick事件。有没有什么办法可以改变这种行为,或发现该事件被解雇通过点击,而不是文本框的身体?

This works exactly as I would like; however, when the VerticalScrollBars are visible, if you rapidly click the ScrollBar the txtComments_MouseDoubleClick event is fired. Is there any way I can change this behavior or detect that the event was fired by clicking the ScrollBar instead of the body of the textbox?

我想这样做的主要原因是,如果你试图通过双击滚动条的事件被触发这会导致应用程序走这条路,这是很烦人的,如果不是用户向下滚动打算采取行动。

The main reason I want to do this, is that if you try to scroll down by double clicking the scroll bars the event is fired which causes the application to go down that path, which is very annoying if that is not the users intended action.

推荐答案

在你双击处理程序,检查 OriginalSource 属性上的 MouseButtonEventArgs 的。该源会告诉你,无论是实际的滚动条(重复键),或文本框。是这样的:

In your double-click handler, check the OriginalSource property on the MouseButtonEventArgs. That source will tell you whether it was the actual scrollbar (the repeat button), or the textbox. Something like:

if (e.OriginalSource is TextBox)
{ 
    // Do your stuff.
}
else
{
    // From the scroll-bar.
}

这篇关于快速使用滚动条时,WPF文本框的DoubleClick事件触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆