Tôi có thể sai trong quan điểm của tôi - nhưng ít nhất tôi nhìn một số thời gian trước đây đối với một số chiều dài khá thành InputManager
.
Sơ yếu lý lịch của tôi từ đó là: Việc tạo bọt và tạo đường hầm được thực hiện bởi InputManager
. Tuy nhiên, gọi số uielement.Raise()
sẽ chỉ bao giờ cung cấp sự kiện trực tiếp (bất kể số RoutingStrategy
như Ray Burns đã đề cập đến).
Nhưng (đoán) tùy thuộc vào RoutingStrategy
các InputManager
đi lên và xuống cây thị giác giữa CompositionRoot
và VisualTreeHlper.Hittest()-
ed thị giác và cung cấp đường hầm và các sự kiện bublling.
Có một cách để nâng cao sự kiện thông qua InputManager, nhưng nó không phải là chính thức và cần phản ánh (Tôi có nó từ một bài Stackoverflow):
void RaiseMouseInputReportEvent(Visual eventSource, int timestamp, int pointX, int pointY, int wheel)
{
Assembly targetAssembly = Assembly.GetAssembly(typeof(InputEventArgs));
Type mouseInputReportType = targetAssembly.GetType("System.Windows.Input.RawMouseInputReport");
Object mouseInputReport = mouseInputReportType.GetConstructors()[0].Invoke(new Object[] {
InputMode.Foreground, timestamp, PresentationSource.FromVisual(eventSource),
RawMouseActions.AbsoluteMove | RawMouseActions.Activate,
pointX, pointY, wheel, IntPtr.Zero });
mouseInputReportType.GetField("_isSynchronize", BindingFlags.NonPublic | BindingFlags.Instance)
.SetValue(mouseInputReport, true);
InputEventArgs inputReportEventArgs = (InputEventArgs)targetAssembly
.GetType("System.Windows.Input.InputReportEventArgs")
.GetConstructors()[0]
.Invoke(new Object[] {
Mouse.PrimaryDevice,
mouseInputReport });
inputReportEventArgs.RoutedEvent = (RoutedEvent)typeof(InputManager)
.GetField("PreviewInputReportEvent", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)
.GetValue(null);
bool handled = InputManager.Current.ProcessInput((InputEventArgs)inputReportEventArgs);
}