2

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.

Community
  • 1
  • 1
Nikzeno
  • 116
  • 8
  • sorry i can not test this one but you can. add a rectangle with the same command with commandparameters 'CommandParameter="{Binding ElementName=Rectangle}' and ellipse for 'CommandParameter="{Binding ElementName=Ellipse}' and of course change your messagebox `Pippo = new RelayCommand(x => MessageBox.Show(x.ToString()));` and test with your monitor – caner Apr 20 '17 at 12:57
  • "touch on white space, the message box get fired again!" that's not really clear. What is "white space"? If you mean that you're touching outside of the bounds of the ellipse, *are you sure?* A finger is fatter than a mouse cursor. Make sure the white space outside of the ellipse is two or three fingers wide, then touch as far away as possible. Does it still happen? –  Apr 20 '17 at 13:06
  • Also, you can use Snoop to trace events within the application, which may help you understand what's going on. –  Apr 20 '17 at 13:07
  • @caner: no real difference. If I mouse click on the rectangle the msgbox shows System...Rectangle, if I mouse click on the Ellipse it shows System...Ellipse. If I touch the rectangle it shows System...Rectangle, then if I touch the ellipse or the white space it still shows System...Rectangle. – Nikzeno Apr 20 '17 at 15:04
  • @Will: yes, I'm sure of touching out of the ellipse. I edited my answer to show some info shown by Snoop (thanks for the tip). – Nikzeno Apr 20 '17 at 15:06

1 Answers1

1

It seems to me that this post by Microsoft solves the issue, even though I see here somebody complaines about crashes on some hardware.

Nikzeno
  • 116
  • 8