我使用TabControl - > ScrollViewer - >与pMouseLeftButtonDown处理程序对接....我的目标是实现一个拖动滚动滚动查看器... 我有一个自定义scrollviewer,我取消所有previewmouseleftbuttondown事件(模板内边框上的处理程序):
private void pMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (!block)
{
block = true;
lastPreviewMouseDownMouseButtonEventArgs = null;
return;
}
else
{
block = true;
}
lastPreviewMouseDownMouseButtonEventArgs = null;
mouseDragStartPoint = e.GetPosition(this);
scrollStartOffset.X = HorizontalOffset;
scrollStartOffset.Y = VerticalOffset;
e.Handled = true;
lastPreviewMouseDownMouseButtonEventArgs = e;
}
在某些特殊情况下,我想手动触发“lastPreviewMouseDownMouseButtonEventArgs”。这似乎有效,因为在raiseEvent()调用之后,再次调用方法pMouseLeftButtonDown()并且不会阻止此新事件(processed = true)。问题是ui元素没有鼠标事件=>没有鼠标左键按下,这意味着没有选项卡选择...
问题出在哪里?
FrameworkElement el = lastPreviewMouseDownMouseButtonEventArgs.Source as FrameworkElement;
lastPreviewMouseDownMouseButtonEventArgs.Handled = false;
Debug.WriteLine(el);
MouseButtonEventArgs newEvent = new MouseButtonEventArgs(Mouse.PrimaryDevice, Environment.TickCount, MouseButton.Left) { RoutedEvent = FrameworkElement.MouseLeftButtonDownEvent };
el.RaiseEvent(lastPreviewMouseDownMouseButtonEventArgs);
答案 0 :(得分:0)
我不确定它是否真的有用,但你需要改变:
FrameworkElement el = lastPreviewMouseDownMouseButtonEventArgs.Source as FrameworkElement;
为:
FrameworkElement el = lastPreviewMouseDownMouseButtonEventArgs.OriginalSource as FrameworkElement;
您可能还需要同时提出PreviewMouseButtonDown
和MouseButtonDown
事件。同样,不确定这样做是否真的能满足您的需求。
相反,为什么不直接获取被点击的TabItem,并设置IsSelected = true
?