文本框的动态丢失焦点事件会引发错误

时间:2014-04-16 15:21:12

标签: c# xaml windows-phone-8

失去焦点事件代码:

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);

引发以下错误: - 无法隐式转换类型&#39; System.EventHandler&#39;到&#39; System.Windows.RoutedEventHandler&#39;

1 个答案:

答案 0 :(得分:2)

LostFocus事件需要RoutedEventHandler,而不是EventHandler

myTextBox1j.LostFocus += new RoutedEventHandler(myTextBox_LostFocus);

这也应该有效:

myTextBox1j.LostFocus += myTextBox_LostFocus;