簡體   English   中英

用於onFocus的TextBox addHandler以編程方式wp7

[英]TextBox addHandler for onFocus programmatically wp7

我試圖將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                            
   }
 }

在上面的代碼中,我想為所有子TextBoxes onFocus添加一個事件處理程序。

但是這里關於invalid arguments錯誤,任何人都可以解決嗎?

解決了問題--->

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