[英]TextBox addHandler for onFocus programmatically wp7
我試圖將event handler
添加到grid
的textboxes
,以便我將下面的代碼編寫為--->
// 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.