将自己的事件添加到WPF控件涉及什么?

时间:2012-02-21 11:04:32

标签: c# wpf events event-handling touch

我经常不得不在我的WPF项目中使用TouchDown / TouchUp事件来检测“双击”;有时在列表框上,有时是按钮,有时是telerik控件。我如何为这些控件添加DoubleTap事件和事件处理程序?工作太大了?

2 个答案:

答案 0 :(得分:1)

您可以创建一个使用对控件和委托函数的引用构造的类。 (请原谅我不完美的语法[如果它不完美],我在内存中键入此内容)

public class DoubleTap {
    delegate void ActionFunction();
    Control ReferencedControl;
    public DoubleTap ( ref Control referencedControl , delegate actionFunction ) {
        ActionFunction = actionFunction;
        ReferencedControl = referencedControl;
        // apply TouchDown and TouchUp event handlers to ReferencedControl
    }
    // Put your TouchDown and TouchUp functions for testing the double tap here
    // when double tap tests as true then call ActionFunction();
}

答案 1 :(得分:0)

您必须为此使用行为。这将包括从System.Windows.Interactivity.Behavior创建派生类型并覆盖TouchDown / TouchUp的OnAttached方法。

有关如何实施行为,请参阅WPF Tutorial | BehaviorsIntroduction to Attached Behaviors in WPF

相关问题