本文介绍了手势服务 OnFlick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在代码隐藏中(即不在 XAML 中)为 Flick 事件添加 GestureService 和处理程序?

How can I add the GestureService and a handler for the Flick event in code-behind (i.e. not in XAML)?

推荐答案

首先,确保您已添加对 的引用Silverlight Toolkit for Windows Phone 7,特别是 Microsoft.Phone.Controls.Toolkit.dll 程序集.然后确保您有 Microsoft.Phone.Controls 命名空间的 XML 命名空间引用:

Firstly, make sure you've added a reference to the Silverlight Toolkit for Windows Phone 7, specifically the Microsoft.Phone.Controls.Toolkit.dll assembly. Then make sure you have an XML namespace reference for the Microsoft.Phone.Controls namespace:

xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"

然后,将 GestureService.GestureListener 添加到要处理手势的控件中:

Then, add the GestureService.GestureListener to the control you want to handle gestures on:

<TextBlock x:Name="test" Text="Test">
    <toolkit:GestureService.GestureListener>
        <toolkit:GestureListener Flick="TextBlock_Flick" />
    </toolkit:GestureService.GestureListener>
</TextBlock>

然后你只需要在事件处理程序中实现你的逻辑.

Then you just need to implement your logic in the event handler.

更新:上述方法是针对在XAML中使用GestureService;要在代码隐藏中使用 GestureService,请使用 GetGestureListener 方法:

Update: The above approach is for using the GestureService in XAML; to use the GestureService in code-behind you use the GetGestureListener method:

var listener = GestureService.GetGestureListener(this.test);
listener.Flick += this.TextBlock_Flick;

这篇关于手势服务 OnFlick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 13:31