问题描述
我正在尝试通过使用以下代码将VisualBasic
冒出来升级MouseLeftButtonDownEvent。 MouseButtonEventArgs args = new MouseButtonEventArgs(Mouse.PrimaryDevice,0,MouseButton.Left);
args.RoutedEvent = UIElement.MouseLeftButtonDownEvent;
args.Source = this;
RaiseEvent(args);
由于某些原因,较高级别的组件未收到此冒泡事件。
我是忽略某些东西,还是无法提起这个鼠标事件
你的问题是你正在提高一个事件不起泡。
MouseLeftButtonDownEvent
被定义为 RoutingStrategy.Direct
,这意味着它被路由到只接收事件的控件。
你想使用 Mouse.MouseDownEvent
事件。 UIElement
和其他类内部转换为一个 MouseLeftButtonDownEvent
。确保将e.ChangedButton设置为 MouseButton.Left
:
RaiseEvent (new MouseButtonEventArgs(Mouse.PrimaryDevice,0,MouseButton.Left)
{
RoutedEvent = Mouse.MouseDownEvent,
Source = this,
});
I am trying ot raise a MouseLeftButtonDownEvent by bubbling it up the Visual treewith the following code.
MouseButtonEventArgs args = new MouseButtonEventArgs(Mouse.PrimaryDevice,0, MouseButton.Left);
args.RoutedEvent = UIElement.MouseLeftButtonDownEvent;
args.Source = this;
RaiseEvent(args);
For some reason the higher level components are not receiving this bubbled event.Am I overlooking something or is it not possible to raise this Mouse event
Your problem is that you are raising an event that does not bubble.
MouseLeftButtonDownEvent
is defined as RoutingStrategy.Direct
, which means it is routed to only the control receiving the event.
You want to use Mouse.MouseDownEvent
event instead. UIElement
and other classes internally convert this into a MouseLeftButtonDownEvent
. Make sure you set e.ChangedButton to MouseButton.Left
:
RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left)
{
RoutedEvent = Mouse.MouseDownEvent,
Source = this,
});
这篇关于提高WPF MouseLeftButtonDownEvent事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!