我正在MVVM项目中实现此处描述的解决方案:http://nui.joshland.org/2010/04/why-wont-wpf-controls-work-with-touch.html
但问题是,如果我在XAML中的UserControl中实现TouchDown和TouchUp事件处理程序,那么我遇到一个问题,其他GroupView无法再获取用于轻弹的窗口消息 - 或者无法处理轻弹因此,他们的关联窗口消息永远不会被发送。
视图的自上而下结构是: ButtonsView - 具有Touch事件处理程序 GroupView - 具有鼠标事件处理程序和Flicks事件处理程序
我在代码隐藏中使用它来挂钩电影并处理它们:
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很新。 感谢
答案 0 :(得分:0)
我通过在ButtonsView中捕获鼠标事件和轻弹事件来解决这个问题,这样他们就不会向下隧道到GroupView。