views:

387

answers:

1

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" />

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.

+4  A: 

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.
}
Charlie
That myfriend is probably the best answer I've ver got here. It was **EXACTLY** what I needed. Thanks!
Nate Bross
You're welcome! :)
Charlie
One up from me too, thank you!Note: I had to modify TextBox to TextBlock, maybe this can help someone.
m.bagattini