Solved

XAML Textbox Clearing When User Starts To Type

Posted on 2013-01-31
4
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

630 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