Dodsworth
asked on
XAML Textbox Clearing When User Starts To Type
I have an XAML Textbox that kind of acts as it's own Label.
Like the Experts Exchange search box.
Mine reads "Enter a search term"
Unlike the EE example, where the text clears on mouseenter, I'm using Windows Phone and programmatically set the focus to the textbox, so I need "Enter a search term" to disappear when the user starts to type.
I wrote this...
... which works fine unless the search term happens to begin with a number. I think it must be something to do with the keyboard switching key ?
Ideas Experts?
Like the Experts Exchange search box.
Mine reads "Enter a search term"
Unlike the EE example, where the text clears on mouseenter, I'm using Windows Phone and programmatically set the focus to the textbox, so I need "Enter a search term" to disappear when the user starts to type.
I wrote this...
Private Sub tSearch_Keydown(sender As Object, e As KeyEventArgs)
If tSearch.Text = "Enter a search term" Then
tSearch.Text = e.Key.ToString
tSearch.SelectionStart = 2
tSearch.SelectionLength = 0
End If
End Sub
... which works fine unless the search term happens to begin with a number. I think it must be something to do with the keyboard switching key ?
Ideas Experts?
ASKER
I have tried selecting the current text before but in windows phone it displays the selection markers (changes colour and places little lines and circles)
ASKER
help! pls
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Private Sub tSearch_GotFocus(sender As Object, e As System.EventArgs) Handles tSearch.GotFocus
tSearch.SelectAll
End Sub