System.Windows.RoutedEventArgs cannot be converted to type System.Windows.Input.MouseButtonEventArgs

Posted 棉晗榜

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了System.Windows.RoutedEventArgs cannot be converted to type System.Windows.Input.MouseButtonEventArgs相关的知识,希望对你有一定的参考价值。

C#后台代码触发按钮点击事件,下面的K1是一个Label,触发了鼠标点击左键事件

 private void Window_Activated(object sender, EventArgs e)
  
      //初始化点击:首页。后台代码触发          
      // K1.RaiseEvent(new RoutedEventArgs(MouseLeftButtonUpEvent));
      K1.RaiseEvent(
              new System.Windows.Input.MouseButtonEventArgs(
              Mouse.PrimaryDevice, 1, MouseButton.Left)
              
                  RoutedEvent = MouseLeftButtonUpEvent
              
          );
  

最终执行的事件

  private void Label_MouseUp(object sender, MouseButtonEventArgs e)
  
     var obj = sender as Label;
  

参考资料
https://stackoverflow.com/questions/29364751/how-to-invoke-mousedoubleclick-on-button-code-behind

以上是关于System.Windows.RoutedEventArgs cannot be converted to type System.Windows.Input.MouseButtonEventArgs的主要内容,如果未能解决你的问题,请参考以下文章