2013-05-04 54 views
0

我試圖一個event handlergrid 添加到textboxes讓我心中已經下面寫--->文本框addHandler操作的聚焦狀態編程WP7

// some code 
foreach (var child in (o as Grid).Children) 
{ 
    if (child.GetType() == typeof(TextBox)) 
    { 
    child.AddHandler(OnGotFocus, new RoutedEventHandler(TextBox_GotFocus), true); //<---error        
    } 
} 

的代碼在上面的代碼我想補充所有子女TextBoxesonFocus事件處理程序。

但它在這裏得到一些錯誤關於invalid arguments,任何一個可以解決這個問題嗎?

+0

什麼是確切的錯誤信息? – nemesv 2013-05-04 12:50:55

回答

0

解決了這個問題--->

txtBox.GotFocus += (sender, eargs) => 
           { 
            if (txtBox.Text == StartingText[index]) 
             txtBox.Text = ""; 
           }; 

txtBox.LostFocus += (sender, eargs) => 
           { 
            if (txtBox.Text == "") 
             txtBox.Text = StartingText[index]; 
           };