C# 向RoutedEventHandler发送事件处理程序
以下是我拥有的代码的基本模型:C# 向RoutedEventHandler发送事件处理程序,c#,windows-phone-7,C#,Windows Phone 7,以下是我拥有的代码的基本模型: private void textBlock1_Tap (object sender, System.Windows.Input.GestureEventArgs e) { TextBox TextBox1 = new TextBox(); TextBlock tblk = (TextBlock)sender; ApplicationBar = new ApplicationBar(); TextBox1.LostFocus +
private void textBlock1_Tap (object sender, System.Windows.Input.GestureEventArgs e)
{
TextBox TextBox1 = new TextBox();
TextBlock tblk = (TextBlock)sender;
ApplicationBar = new ApplicationBar();
TextBox1.LostFocus += TextBox1_LostFocus;
ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/check.png", UriKind.Relative));
appBarButton.Text = "Accept";
ApplicationBar.Buttons.Add(appBarButton);
appBarButton.Click +=
}
void TextBox1_LostFocus(object sender, RoutedEventArgs e)
{
//do things here
}
我需要订阅click事件,当它被触发时,我需要调用TextBox1_LostFocus并将TextBox1作为参数发送。基本上,我想做的是制作appBarButton。单击执行与TextBox1.LostFocus完全相同的操作
问题是,LostFocus是RoutedEventHandler,TextBox1_LostFocus在appBarButton.Click是事件处理程序时将RoutedEventTargets作为参数
我在编码方面不是很有经验,所以非常感谢您的帮助
RoutedEventArgs
继承EventArgs
您可以向这两个事件添加相同的处理程序
更好的是,您可以将代码移动到一个函数中,并从两个不同的事件处理程序调用它。谢谢您的回复。到目前为止,我的想法是:1。将TextBox1_LostFocus的第二个参数更改为EventArgs 2。处理click事件的代码行:appBarButton.click+=newEventHandler(TextBox1_LostFocus(TextBox1,);我不知道该怎么做,明白了!