Solved

XAML Textbox Clearing When User Starts To Type

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

11 Experts available now in Live!

Get 1:1 Help Now