Question

I want to Empty The Text which is by default written in the textbox , i can empty it by doing

Textbox1.Text="";

but i want to know, which event should i exactly use ?will it be GotFocus,KeyEnter,Keyup,Tap or any other method .

Was it helpful?

Solution

One simple way is using on GotFocus and LostFocus. On GotFocus the code should be something like this:

if (textbox1.Text == "My default text...")
            textbox1.Text = "";

Just to make sure to no delete a text previously entered by the user. And on LostFocus just something like this:

if (String.IsNullOrWhiteSpace(textbox1.Text))
            textbox1.Text = "My default text...";

So again you are checking to no delete a user entered text.

Hope this helps

OTHER TIPS

You can use PhoneTextBox of WPToolkit, which will maintain that functionality on its own

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top