Solved

XAML Textbox Clearing When User Starts To Type

Posted on 2013-01-31
4
255 Views
Last Modified: 2014-11-12
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...

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

Open in new window


... 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?
0
Comment
Question by:Dodsworth
  • 2
4 Comments
 
LVL 18

Expert Comment

by:UnifiedIS
ID: 38840529
Try moving your logic to the GotFocus event and automatically select all the current text.  Then when typing begins, it clears the value that is there.  

Private Sub tSearch_GotFocus(sender As Object, e As System.EventArgs) Handles tSearch.GotFocus
                tSearch.SelectAll
End Sub
0
 
LVL 1

Author Comment

by:Dodsworth
ID: 38841349
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)
0
 
LVL 1

Author Comment

by:Dodsworth
ID: 38856144
help! pls
0
 
LVL 16

Accepted Solution

by:
CuteBug earned 500 total points
ID: 38887884
What you are looking for is a custom watermark textbox.

Have a look here
http://www.c-sharpcorner.com/UploadFile/74f20d/create-a-watermark-textbox-effect-from-window-phone-7/

(P.S. The code is in CSharp)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now