Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

XAML Textbox Clearing When User Starts To Type

Posted on 2013-01-31
4
Medium Priority
?
268 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 2000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

886 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