views:

465

answers:

1

I am using a WPF ListView with an always visible vertical scrollbar. I have a MouseLeftButtonUp event handler on the ListView. The handler is working properly except when the vertical scrollbar is clicked when it has nothing to do i.e. the ListView box doesn't have enough items to do any scrolling.

In that case nothing should happen as the user has clicked on the vertical scrollbar just to make sure there are no items just off the screen. However the ListView fires the MouseLeftButtonUp event. If the vertical scrollbar does have some work to do the event does not get fired.

Here is my simplifiewd XAML

<ListView MouseLeftButtonUp="DoSomething_MouseLeftButtonUp" SelectionMode="Single" ScrollViewer.VerticalScrollBarVisibility="Visible">
  <ListView.View>
    <GridView>
      <GridViewColumn Width="170" Header="Venue" DisplayMemberBinding="{Binding Path=Venue}" />
    </GridView>
  </ListView.View>
</ListView>

Is there anyway to prevent the MouseLeftButtonUp event firing when the vertical scroll bar is clicked irespective of whether the scroll bar has any work to do or not?

A: 

This is similar to this question, and the answer is the same. In your MouseLeftButtonUp handler, check the MouseButtonEventArgs.OriginalSource property. That will tell you where the click originated.

Charlie
In my own GridView, I have many columns containing an image, textblocks, textblocks with Runs... am I supposed to check for all those?
Elmo Gallen