【问题标题】:Dynamic Lost Focus Event for a text Box throws error文本框的动态丢失焦点事件引发错误
【发布时间】:2014-04-16 15:21:11
【问题描述】:

失去焦点事件代码:

public void myTextBox_LostFocus(object sender, System.Windows.Input.GestureEventArgs e)
    {
        string name = ((TextBox)sender).Name;

        string strl = "tbox" + name.Substring(4);
        TextBox text = FindTextBoxByName(strl);

        text.HorizontalAlignment = HorizontalAlignment.Left;
        text.Width = 50;
        text.Height = 40;
    }

事件调用:-

 myTextBox1j.LostFocus += new EventHandler<GestureEventArgs>(myTextBox_LostFocus);

引发以下错误:- 无法将类型“System.EventHandler”隐式转换为“System.Windows.RoutedEventHandler”

【问题讨论】:

    标签: c# xaml windows-phone-8


    【解决方案1】:

    LostFocus 事件需要 RoutedEventHandler,而不是 EventHandler

    myTextBox1j.LostFocus += new RoutedEventHandler(myTextBox_LostFocus);
    

    这应该也可以:

    myTextBox1j.LostFocus += myTextBox_LostFocus;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-03
      • 1970-01-01
      • 2011-04-21
      • 1970-01-01
      • 1970-01-01
      • 2018-03-15
      • 2012-07-19
      • 1970-01-01
      相关资源
      最近更新 更多