gpt4 book ai didi

wpf - 引发 WPF MouseLeftButtonDownEvent 事件

转载 作者:行者123 更新时间:2023-12-03 23:27:45 26 4
gpt4 key购买 nike

我正在尝试通过在 Visual 树中向上冒泡来引发 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,
});

关于wpf - 引发 WPF MouseLeftButtonDownEvent 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2421304/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com