Solved

XAML Textbox Clearing When User Starts To Type

Posted on 2013-01-31
4
256 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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