1

I was trying to make simple Windows mobile app. In which there is login and registration

I want to know how to code this textbox.text value remove when user focuse or click on it. Like WE do in HTML5 .

<input type="text" name="user" placeholder="User Name "/>

This how we do in html5 and the text disappear. That I want know how to do it in window app

<TextBox Height="72" HorizontalAlignment="Left" Margin="28,254,0,0" 
         Name="Username" Text="" VerticalAlignment="Top" Width="422" />
King King
  • 61,710
  • 16
  • 105
  • 130
Abdul Samad Khan
  • 102
  • 1
  • 2
  • 10

3 Answers3

3

You can use the GotFocus Event:

<TextBox Height="72" HorizontalAlignment="Left" Margin="28,254,0,0" 
         Name="UsernameTextBox" Text="" VerticalAlignment="Top" Width="422" 
         GotFocus="YourGotFocusEvent"/>

In code Behind:

public void YourGotFocusEvent(object sender, RoutedEventArgs e)
{
   UsernameTextBox.Text = string.empty;
   // if you want this to happen only the first time you can remove the event handler like this
   UsernameTextBox.GotFocus -= YourGotFocusEvent;
}
paparazzo
  • 44,497
  • 23
  • 105
  • 176
Luca Perotti
  • 196
  • 1
  • 8
0

or handle a Click event. double-click a button in designer and then write

this.Text= string.empty
WholeLifeLearner
  • 455
  • 4
  • 19
0

For water-mark style text box, you can check out the following UI library. MahApps provides a set of attached properties for the textbox that allows you to do watermark quite easilly.

See this link -> http://mahapps.com/controls/textbox.html

aggietech
  • 978
  • 3
  • 16
  • 38