MessageBox 锁定 TouchInput
MessageBox locks TouchInput
请查看这个蹩脚的 WPF MVVM 应用程序:
<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"));
}
}
运行 然后用鼠标点击,一切正常。
但是如果你使用触摸显示器,你触摸椭圆,消息框打开,用 ok 关闭它,触摸白色 space,消息框再次触发!切换到鼠标,一切正常。
为什么触摸输入会被锁定?以及如何防止这种情况?
我在两个不同的显示器以及 Win 7 和 Win 8 上验证了这一点。
使用 Interactivity 而不是 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>
任何建议将不胜感激。
编辑:
我按照 Will 的建议使用了 Snoop 来获取更多信息。在事件列表中,我看到以下内容:当我单击 window 白色 space 时,鼠标单击事件从 MainWindow 转到 Border,然后返回。
如果我触摸,我有 PreviewTouchDown(赢得边框)、TouchDown(赢得边框)、PreviewTouchMove(赢得边框)、TouchMove(赢得边框)、PreviewMouseDown(赢得边框、AdornerDecorator、contentpresenter、StackPanel、Ellipse).. .和其他更多。
为什么 PreviewMouseDown 会转到 AdornerDecorator 并向下转到 Ellipse?
触摸输入似乎没有更新触摸位置。
编辑 2:
I found this issue reported here as well,但我不知道如何将该解决方案应用到我的案例中。
P.s。我知道在 MVVM 中,ViewModel 不应该引发 MessageBoxes。这只是一个简化的例子。
我觉得 this post by Microsoft solves the issue, even though I see here somebody complaines about crashes on some hardware.
请查看这个蹩脚的 WPF MVVM 应用程序:
<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"));
}
}
运行 然后用鼠标点击,一切正常。
但是如果你使用触摸显示器,你触摸椭圆,消息框打开,用 ok 关闭它,触摸白色 space,消息框再次触发!切换到鼠标,一切正常。
为什么触摸输入会被锁定?以及如何防止这种情况?
我在两个不同的显示器以及 Win 7 和 Win 8 上验证了这一点。
使用 Interactivity 而不是 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>
任何建议将不胜感激。
编辑:
我按照 Will 的建议使用了 Snoop 来获取更多信息。在事件列表中,我看到以下内容:当我单击 window 白色 space 时,鼠标单击事件从 MainWindow 转到 Border,然后返回。 如果我触摸,我有 PreviewTouchDown(赢得边框)、TouchDown(赢得边框)、PreviewTouchMove(赢得边框)、TouchMove(赢得边框)、PreviewMouseDown(赢得边框、AdornerDecorator、contentpresenter、StackPanel、Ellipse).. .和其他更多。 为什么 PreviewMouseDown 会转到 AdornerDecorator 并向下转到 Ellipse?
触摸输入似乎没有更新触摸位置。
编辑 2: I found this issue reported here as well,但我不知道如何将该解决方案应用到我的案例中。
P.s。我知道在 MVVM 中,ViewModel 不应该引发 MessageBoxes。这只是一个简化的例子。
我觉得 this post by Microsoft solves the issue, even though I see here somebody complaines about crashes on some hardware.