点击文本框后,删除文本 [英] Remove text after clicking in the textbox
问题描述
当你启动应用程序,文字的文本框的hello将出现。
When you activate an application, a textbox with text "hello" will appear.
我的问题是:
当你为了点击文本框,使输入数据,我想在XAML code自动删除的文字,我怎么办呢?
My question is:
When you click on the textbox in order to make input data, I want to remove the text automatically in XAML code, how do I do it?
推荐答案
处理的<一个href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.gotfocus.aspx"><$c$c>UIElement.GotFocus$c$c>事件,并在处理程序,清除文本。您还需要删除的处理程序,所以如果你点击文本框
你不会失去你已经进入了一个什么第二次。
Handle the UIElement.GotFocus
event, and in the handler, clear the text. You'll also want to remove the handler, so that if you click on the TextBox
a second time you don't lose what you've already entered.
事情是这样的:
XAML:
<TextBox Text="Hello" GotFocus="TextBox_GotFocus" />
code-背后:
Code-behind:
public void TextBox_GotFocus(object sender, RoutedEventArgs e)
{
TextBox tb = (TextBox)sender;
tb.Text = string.Empty;
tb.GotFocus -= TextBox_GotFocus;
}
这篇关于点击文本框后,删除文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!