WPF 触摸事件 +轻弹?
我正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过捕获 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.