我设法在 C# 中动态创建文本框。当atextbox
有文字时,我可以让它在我点击它时消失吗?
我需要在文本框中输入一个词,这是 Oracle 中选择的结果。
为 TextBox 的 Text 属性赋值。然后您可以订阅 GotFocus 事件,并将文本值设置为空字符串。
// Holds a value determining if this is the first time the box has been clicked
// So that the text value is not always wiped out.
bool hasBeenClicked = false;
private void TextBox_Focus(object sender, RoutedEventArgs e)
{
if (!hasBeenClicked)
{
TextBox box = sender as TextBox;
box.Text = String.Empty;
hasBeenClicked = true;
}
}