WPF ListViewItem events not firing properly on Touchscreen WPF ListViewItem events not firing properly on Touchscreen wpf wpf

WPF ListViewItem events not firing properly on Touchscreen


<configuration>  <runtime>    <AppContextSwitchOverrides value="Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport=true" />  </runtime></configuration>

Finally found a fix.I put the above in my config file, and issue resolved.

Thanks for all the responses.


Summary

  • Never use Click event in ListView/ListBox, use PreviewMouseDown instead.
  • Your touch device may have a low touch precision than most of the others.

Details

I was suffering from the same issue several years ago and found that it behaviors different on different touch devices. On most touch devices, the touch works every time. But on some others, touch may be lost randomly.

If you try to notice your movement tapping on the touchscreen, you may find that the touch will be lost if your finger moves a very little distance away on pressing. This behavior only happens on ListViewItem or ListBoxItem because the ListView and the ListBox handle the touch events and reraises them for their touch-scrolling behavior.

MouseDown and MouseUp on the same control makes a Click event, so are the touch events. But on a ListBox or a ListView, the click events must be in the same point instead of the same control. Because that the ListView/ListBox has no need to handle mouse events first, so the mouse click works fine.

What makes the difference between different kind of touch devices is the touch precision of them. The lower the precision is, the more touch events will be lost.

What you can do is:

  • Never use Click event in ListView/ListBox, use PreviewMouseDown instead.


I know this question is rather old, but maybe someone else is coming here looking for a solution to this problem, like me. walterlv desribed the problem very well. If you don't need touch-scrolling Behaviour of ListView and you are interested in the SelectionChanged event, you can add this to your ListView:

<ListView.ItemContainerStyle>   <Style TargetType="ListViewItem">      <Style.Triggers>         <Trigger Property="IsStylusOver" Value="True">            <Setter Property="IsSelected" Value="True"/>         </Trigger>      </Style.Triggers>   </Style></ListView.ItemContainerStyle>

This way, every touch on a ListViewItem reliably selects it and fires a SelectionChanged event.