2016-02-05 85 views
1

创建任何事件处理程序时没有选项我知道我可以将自己的参数传递给事件处理程序。扩展Wpf MouseButtonEventArgs以启用自定义参数

例如MouseDown事件,

void TxblckLineNum_MouseDown(object sender, RoutedEventArgs e) 
{ 
    //do stuff with e ... 
} 

我需要通过e参数,所以我尝试了各种EventArgs类派生内的一些更多的属性,我无法使用其中的任何e

将一些额外数据传递给事件处理程序的最佳方法是什么?

回答

1
TxblckLine.MouseDown += new System.Windows.Input.MouseButtonEventHandler((s, e) => TxblckLineNum_MouseDown(s, e, SomePar, SomeOtherPar)); 


void TxblckLineNum_MouseDown(object sender, RoutedEventArgs e, string SomePar, int SomeOtherPar) 
{ 
    //do stuff with SomePar/SomeOtherPar... 
}