0

i am trying to add a event handler to the textboxes in a grid so that i'v written the code below--->

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

in above code i want to add an event handler for onFocus for all child TextBoxes.

but its getting some error here about invalid arguments, can any one fix this?

4

1 回答 1

0

解决了问题--->

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

txtBox.LostFocus += (sender, eargs) =>
                                {
                                    if (txtBox.Text == "")
                                        txtBox.Text = StartingText[index];
                                };
于 2013-05-04T13:25:45.263 回答