wpf - 引发 WPF MouseLeftButtonDownEvent 事件

标签 wpf events raise

我正在尝试通过在 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/

相关文章:

.net - 检索 Windows "Window Color"

javascript - 在文本框中粘贴某些文本时是否检查数字(没有设置超时)

events - Powerpoint VBA App_SlideShowBegin

python - 在 python 1.5.2 中获取异常类型

python - 在 Python 中引发错误的一种非常优雅的方式是什么

c# - 通过代码更改 Telerik WPF 按钮颜色

c# - 使用 MVVM 模式 C# 进行实时编辑

c# - 在 C# 中以正确的方式删除特权枚举标志

c# - 在 C# 中引发忽略处理程序引发的异常的事件

android - CardView动画: raise and expand on click?