WPF 触摸事件 +轻弹?

发布于 2024-12-22 20:34:07 字数 1604 浏览 1 评论 0原文

我正在 MVVM 项目中实现此处描述的解决方案: http://nui.joshland.org/2010/04/why-wont-wpf-controls-work-with-touch.html

但问题是,如果我实现我的 XAML 中的 UserControl 中的 TouchDown 和 TouchUp 事件处理程序然后遇到了一个问题,即其他 GroupView 无法再获取轻拂的窗口消息 - 或者轻拂无法被处理,因此永远不会发送其关联的窗口消息。

视图的自上而下的结构是: ButtonsView——具有触摸事件处理程序 GroupView - 具有鼠标事件处理程序和轻拂事件处理程序

我在代码隐藏中使用它来挂钩轻拂并处理它们:

    private void UserControl_Loaded(object sender, RoutedEventArgs e)
    {
        HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
        source.AddHook(WndProc);
    }

    private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
    {
        if (msg == Flicks.WM_TABLET_FLICK)
        {
            Flick flick = Flicks.ProcessMessage(lParam, wParam);
            if (flick != null)
            {
                if (flick.Data.Direction == FLICKDIRECTION.FLICKDIRECTION_LEFT)
                    Scroller("left"); //scrolls left
                else if (flick.Data.Direction == FLICKDIRECTION.FLICKDIRECTION_RIGHT)
                    Scroller("right"); //scrolls right
                else if (flick.Data.Direction == FLICKDIRECTION.FLICKDIRECTION_UP)
                    Scroller("up"); //move up
                else if (flick.Data.Direction == FLICKDIRECTION.FLICKDIRECTION_DOWN)
                    Scroller("down"); //move down
                    handled = true;
            }
        }
        return IntPtr.Zero;
    }

想法/建议?我对 WPF 还很陌生。 谢谢

I am implementing the solution described here in a MVVM project: http://nui.joshland.org/2010/04/why-wont-wpf-controls-work-with-touch.html

But the problem is that if I implement the TouchDown and TouchUp event handlers in the UserControl in my XAML then I run into a problem where other GroupView cannot get the Window Messages for flicks anymore -- OR flicks are not able to be processed so their associated window message are never sent.

The top-down structure of the views is:
ButtonsView -- has Touch event handlers
GroupView -- has Mouse event handlers and the Flicks event handlers

I'm using this in the code-behind to hook the flicks and handle them:

    private void UserControl_Loaded(object sender, RoutedEventArgs e)
    {
        HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
        source.AddHook(WndProc);
    }

    private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
    {
        if (msg == Flicks.WM_TABLET_FLICK)
        {
            Flick flick = Flicks.ProcessMessage(lParam, wParam);
            if (flick != null)
            {
                if (flick.Data.Direction == FLICKDIRECTION.FLICKDIRECTION_LEFT)
                    Scroller("left"); //scrolls left
                else if (flick.Data.Direction == FLICKDIRECTION.FLICKDIRECTION_RIGHT)
                    Scroller("right"); //scrolls right
                else if (flick.Data.Direction == FLICKDIRECTION.FLICKDIRECTION_UP)
                    Scroller("up"); //move up
                else if (flick.Data.Direction == FLICKDIRECTION.FLICKDIRECTION_DOWN)
                    Scroller("down"); //move down
                    handled = true;
            }
        }
        return IntPtr.Zero;
    }

Thoughts/Suggestions? I'm pretty new to WPF.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

各自安好 2024-12-29 20:34:07

我通过捕获 ButtonsView 中的鼠标事件和轻拂事件解决了这个问题,这样它们就不会向下传输到 GroupView。

I solved this by capturing the mouse events and flick events in the ButtonsView so that they wouldn't tunnel down to the GroupView.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文