【问题标题】:Send an EventHandler to a RoutedEventHandleer将 EventHandler 发送到 RoutedEventHandler
【发布时间】:2013-06-12 20:39:45
【问题描述】:

这是我拥有的代码的基本模型:

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
}

我需要订阅点击事件,当它被触发时,我需要调用 TextBox1_LostFocus 并将 TextBox1 作为参数发送。基本上我想做的是让 appBarButton.Click 做与 TextBox1.LostFocus 完全相同的事情。

问题是,LostFocus 是一个 RoutedEventHandler,TextBox1_LostFocus 将一个 RoutedEventArgs 作为参数,而 appBarButton.Click 是一个 EventHandler。

我在编码方面完全没有经验,因此非常感谢任何帮助!

【问题讨论】:

    标签: c# windows-phone-7


    【解决方案1】:

    RoutedEventArgs 继承 EventArgs

    您可以为这两个事件添加相同的处理程序。

    更好的是,您可以将代码移动到一个函数中并从两个不同的事件处理程序中调用它。

    【讨论】:

    • 感谢您的回复。到目前为止,这是我实现它的想法: 1. 将 TextBox1_LostFocus 的第二个参数更改为 EventArgs 2. 处理点击事件的代码行:appBarButton.Click += new EventHandler(TextBox1_LostFocus(TextBox1, ));我不知道如何继续。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-27
    • 2019-09-11
    相关资源
    最近更新 更多