I have an WPF app running on a touchscreen where the user needs to hold down one button (The HOLD button) to enable a second button (the GO button). The idea is this accidentally prevents the user pressing the GO button without first holding down the HOLD button. The HOLD button can also be activated by holding down the "return" key, which then enables the GO button. This all works fine, except when the user physically holds down the HOLD button and then presses the GO button: GO button touch is not registered. Yes, the device is multitouch compatible...
I would have thought this would be a common issue but have only found these Qs:
Pressing multiple buttons simultaneously
How can I detect 2 button pressed at the same time?
My reading of these old posts suggests that WPF can't really handle a button press when another is held down.
I have tried using standard touch and am now using ManipulationDelta which I hoped would resolve the issue (since the DirectlyOver seems to do what the questions above suggested). Neither seem to work. ManipulationDelta code is below - feedback appreciated if I've stuffed something up.
So my question(s) is:
#1. can WPF actually handle detection of a button touch if the user is already holding down another button? and
#2. If the answer to #1 is "YES" then what is an effective way to approach it?
Many thanks!
public MainWindow()
{
InitializeComponent();
DataContext = new MainViewModel();
// Enable manipulation events
this.ManipulationStarting += Window_ManipulationStarting;
this.ManipulationDelta += Window_ManipulationDelta;
}
private void Window_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
{
e.ManipulationContainer = this;
e.Mode = ManipulationModes.All;
Debug.WriteLine("Manipulation starting");
}
private void Window_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
// Handle multi-touch events
if (e.Manipulators.Count() > 1)
{
var touchDevices = e.Manipulators.OfType<TouchDevice>();
if (holdButton.IsPressed && touchDevices.Any(td => td.DirectlyOver == goButton))
{
goButton.Command.Execute(goButton.CommandParameter);
Debug.WriteLine("GO button command executed");
}
}
Debug.WriteLine("Manipulation delta");
}
Ok so I could not find a way around the mentioned limitations with WPF. So what I did instead was add a brief timer to my HOLD button that keeps the GO button enabled. User touches HOLD then GO. All good. Not exactly what I wanted but close enough to work for the user. Interestingly enough, I've now seen multiple other windoze tablet UIs that use the same approach, so I'm guessing I'm not the only one to run into this issue.