Windows 7 多点触控上的 WPF 按钮按下
我正在开发一个类似 WPF 信息亭的客户端,该客户端将部署在启用多点触控的 HP TouchSmart Windows 7 计算机上。我的问题是,对于 Windows 7 多点触控,应用程序无法将手指“轻击”识别为按钮按下事件,因此永远不会触发按钮按下触发器以更改颜色。
通常会显示 Windows 7 触摸动画,并且按钮单击事件可以正常触发。只有“IsPressed”事件的 XAML 定义样式在手指点击时无法按预期运行。如果用手指施加足够的压力和/或像指纹一样滚动或按压,它最终会起作用。是否有解决方法可以让“点击”触发按下/点击事件?
<Trigger Property="AreAnyTouchesOver" Value="true">
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource PressedOff}" />
</Trigger.ExitActions>
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource PressedOn}" />
</Trigger.EnterActions>
</Trigger>
<Trigger Property="AreAnyTouchesDirectlyOver" Value="true">
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource PressedOff}" />
</Trigger.ExitActions>
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource PressedOn}" />
</Trigger.EnterActions>
</Trigger>
I am developing a WPF kiosk like client that will be deployed on an HP TouchSmart Windows 7 machine with multi-touch enabled. My problem is that with Windows 7 multi-touch, the application does not recognize a finger 'tap' as a button press event, and therefore the button press Trigger to change color is never fired.
The Windows 7 animation for the touch usually displays, and the button click event fires fine. It is only the XAML define style for the 'IsPressed' event that does not function as intended on a finger tap. It does eventually work if enough pressure is applied with a finger and/or you roll or press like you would do for a fingerprint. Is there a workaround for to make a 'tap' fire a press/click event?
<Trigger Property="AreAnyTouchesOver" Value="true">
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource PressedOff}" />
</Trigger.ExitActions>
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource PressedOn}" />
</Trigger.EnterActions>
</Trigger>
<Trigger Property="AreAnyTouchesDirectlyOver" Value="true">
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource PressedOff}" />
</Trigger.ExitActions>
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource PressedOn}" />
</Trigger.EnterActions>
</Trigger>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需将按钮的
Stylus.IsPressAndHoldEnabled
附加属性设置为False
即可。这将导致按钮的 IsPressed 属性被设置/清除以响应触摸和鼠标单击。来自 UIElement.TouchDown 事件 的文档:
例如,您可以在按钮样式中使用设置器来确保该属性设置为 false:
我在尝试找到一种方法使我的按钮能够可靠地为鼠标单击和触摸事件设置动画时发现了这个问题。接受的答案让我走上了一条似乎错误的道路:将故事板与触摸向上/向下事件同步。事实证明,使用
IsPressed
属性触发器既简单又可靠。希望这可以避免其他人犯类似的错误。Simply set the
Stylus.IsPressAndHoldEnabled
attached property toFalse
for the button. This will cause the button'sIsPressed
property to be set/cleared in response to a touch as well as a mouse click.From the documentation for the UIElement.TouchDown Event:
For example, you could use a setter in your button style to make sure the property is set to false:
I found this question while trying to find a way to make my button reliably animate for both mouse clicks and touch events. The accepted answer sent me down what seems to be the wrong path: Synchronizing storyboards with touch up/down events. Using the
IsPressed
property trigger for both has proven to be simple and reliable. Hopefully this saves someone else from making a similar mistake.我不清楚你想做什么。
关于您的问题的一些解释:
在触摸中,仅当您的接触按住元素并且移动阈值被传递以创建“按下”时,才会触发 IsPressed (这就是为什么如果您按下手指并稍微滑动它,您会看到它)
一旦联系人出现,IsPressed = false。
当您“点击”按钮时,您实际上是在单击鼠标。这就是事件按预期触发的原因。
那么你究竟想做什么?您希望在“按住”按钮(“IsPressed”)或单击(点击)按钮时触发故事板动画。
这是两种不同的情况,还请注意,桌面隐喻通常不能很好地转换为触摸环境。您可能需要重新考虑如何向用户提供视觉反馈。
如果我正确理解你的问题,我认为你想要的最简单的答案是触发“TouchDown”。
更新:
这应该适用于 TouchDown 触发器
注意:我面前没有触摸屏,因此可能会出现错误,但看起来是正确的。
I am not clear on what you want t do.
Some explanation on your issue:
In touch IsPressed is only triggered when your contact is held down over the element and the movement threshold is passed to create a "press" (That is why you see it if you press the finger down and slide it slightly)
As soon as the contact comes up IsPressed = false.
When you "tap" a button you are in essence doing a mouse click. This is why events fires as expected.
So what exactly are you trying to do? You want to fire an storyboard animation when a button is "held down" ("IsPressed") or when a button is clicked (tapped).
These are two different situations, also note that often times desktop metaphors do not translate well to the touch environment. You may want to rethink how you are giving visual feedback to the user.
I think the easiest answer for what you want to is Trigger on "TouchDown" if I understand your questions correctly.
UPDATE:
This should work for a TouchDown trigger
NOTE: I don't have a touch screen in front of me so there could be errors but it looks correct.
对于触摸开发,我建议使用 Microsoft® Surface® Toolkit for Windows Touch Beta 在您的项目中,并使用包含的 Surface 控件,因为它们可以正确处理触摸事件,以及多种用例,例如用户用 2 个手指按下按钮,以及一次举起它们一个。只有最后一个“抬起”或 TouchUp 事件才应触发 Click 事件。
所有表面控件都是 Windows 控件的子类,因此 SurfaceListBox 是 ListBox 的子类,SurfaceButton 是 Button 的子类,等等。这样,您的所有样式和模板仍将适用于这些控件。
在您的情况下,您将需要使用 SurfaceButton 控件。只需添加对工具包程序集的引用,然后在外部元素(、等)中添加对表面命名空间的引用,例如
,然后从该命名空间添加表面控件,例如
For touch development, I would recommend using the Microsoft® Surface® Toolkit for Windows Touch Beta in your project, and using the surface controls included, since they handle touch events properly, and a multitude of use cases, such as a user pressing a button with 2 fingers, and lifting them one at a time. Only the last "lift" or TouchUp event should trigger a Click event.
All of the surface controls are subclasses of the Windows controls, so SurfaceListBox subclasses ListBox, SurfaceButton subclasses Button, etc. This way, all your styles and templates will still work with these controls.
In your case, you will want to use the SurfaceButton control. Simply add a reference to the toolkit assemblies, and in your outer element (, , etc), add a reference to the surface namespace, such as
and then add the surface controls from that namespace, such as