简体   繁体   English

用于onFocus的TextBox addHandler以编程方式wp7

[英]TextBox addHandler for onFocus programmatically wp7

i am trying to add a event handler to the textboxes in a grid so that i'v written the code below---> 我试图将event handler添加到gridtextboxes ,以便我将下面的代码编写为--->

// 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 . 在上面的代码中,我想为所有子TextBoxes onFocus添加一个事件处理程序。

but its getting some error here about invalid arguments , can any one fix this? 但是这里关于invalid arguments错误,任何人都可以解决吗?

solved the problem---> 解决了问题--->

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM