please see this lame WPF MVVM app:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<StackPanel>
<Ellipse Fill="Black" Height="40" Width="40">
<Ellipse.InputBindings>
<MouseBinding Gesture="LeftClick" Command="{Binding Pippo}" />
</Ellipse.InputBindings>
</Ellipse>
</StackPanel>
</Window>
ViewModel class:
class ViewModel
{
public ICommand Pippo { get; set; }
public ViewModel()
{
Pippo = new RelayCommand(x => MessageBox.Show("Here I am"));
}
}
Run it and click around with the mouse, everything works as expected.
But if you use a touch monitor, you touch on the ellipse, the message box open, close it with ok, touch on white space, the message box get fired again! Switch to mouse, everything fine again.
Why does the touch input get locked? And how to prevent this?
I verified this on two different monitors and both Win 7 and Win 8.
No luck either using Interactivity instead of the MouseBinding:
<Ellipse Fill="Black" Height="40" Width="40">
<i:Interaction.Triggers>
<i:EventTrigger EventName="TouchUp" >
<i:InvokeCommandAction Command="{Binding Pippo}" />
</i:EventTrigger>
<i:EventTrigger EventName="MouseDown" >
<i:InvokeCommandAction Command="{Binding Pippo}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Ellipse>
Any suggestion will be higly appreciated.
EDIT:
I used Snoop as suggested by Will to get some more info. In the event list I see the following: when I click on the window white space, the mouse click events goeas from the MainWindow to the Border and then way back. If I touch, I have PreviewTouchDown (win to border), TouchDown (border to win), PreviewTouchMove (win to border), TouchMove (border to win), PreviewMouseDown (win to border to AdornerDecorator to contentpresenter to StackPanel to Ellipse)... and other more. How come the PreviewMouseDown goes to the AdornerDecorator and down to the Ellipse?
It looks like the touch input does not update the touch position.
EDIT 2: I found this issue reported here as well, but I do not know how to apply that solution to my case.
P.s. I know in MVVM the ViewModel shouldn't raise MessageBoxes. It's just a simplified example.
It seems to me that this post by Microsoft solves the issue, even though I see here somebody complaines about crashes on some hardware.