Reputation: 354
I am developing a WPF application for use on a point of sale with a touch screen. I have an ItemsControl with product buttons inside a ScrollViewer. The user can scroll (pan) through the products by dragging with their finger. To add a product to the shopping cart, the user simply touches the product button. So far so good.
However, since the touch screen surface is quite smooth and polished, the users's finger sometimes slips a tiny bit when trying to press a button. In that case, the button click is not registered. Instead, the ScrollViewer scrolls for that tiny bit of movement.
Now, my question is: is there a way to reduce the sensitivity of the ScrollViewer, so that it would take a longer drag to initiate scrolling and suppressing the click event.
Thank you for any advice!
Best regards,
Chris
Upvotes: 3
Views: 2140
Reputation: 87
I have the same issue and I am trying to implement the accepted solution (on a listbox). The problem that I have is that OnManipulationDelta never gets fired.
Am I doing this the correct way? (Total WPF noob).
Public Class MyListbox Inherits System.Windows.Controls.ListBox
Shared Sub New()
'This OverrideMetadata call tells the system that this element wants to provide a style that is different than its base class.
'This style is defined in themes\generic.xaml
DefaultStyleKeyProperty.OverrideMetadata(GetType(MyListbox), New FrameworkPropertyMetadata(GetType(MyListbox)))
End Sub
Protected Overrides Sub OnManipulationDelta(e As ManipulationDeltaEventArgs)
Console.WriteLine("Detected" & e.CumulativeManipulation.Translation.Length)
If e.CumulativeManipulation.Translation.Length > 35 Then
MyBase.OnManipulationDelta(e)
Else
e.Handled = True
End If
End Sub
End Class
Upvotes: 0
Reputation: 66
I had same sensitivity problem, and solved it this way:
Created own ScrollViewer, which inherits from native ScrollViewer:
It seems that native control panning treshold is little as 3 pixels and this is why touch click is registered easily as panning. By this trick, you can define your own treshold. I used 35pixels (to be exact, device independent pixels in WPF)
Upvotes: 5
Reputation: 69959
There is a way that you can fulfil your requirements, but I'm not sure if you'll like it... You'll basically need to implement your own custom scrolling logic using the IScrollInfo
Interface. You can do this by implementing the IScrollInfo
Interface in a custom Panel
and simply delaying the calls to scroll by whatever amount you like.
This interface has a fair number of methods and properties that you need to implement, but they are mostly pretty simple... this is a small example to give you an idea how simple they are:
public void LineDown()
{
SetVerticalOffset(VerticalOffset + LineSize);
}
public void LineUp()
{
SetVerticalOffset(VerticalOffset - LineSize);
}
You can get further help by looking at the WPF Tutorial - Implementing IScrollInfo article on the Tech Pro website.
Once you have your custom Panel
that provides the custom scrolling, you simply need to use it in a ScrollViewer
, which you can do in a Resource
:
<ScrollViewer x:Key="CustomScrollViewer">
<YourXmlNamespacePrefix:YourCustomPanel>
<ItemsPresenter ... />
</YourXmlNamespacePrefix:YourCustomPanel>
</ScrollViewer>
Finally, reference your CustomScrollViewer
in whatever collection control that you choose to use. So, it can be done, but can you be bothered to do it?
Upvotes: 0