user765864
user765864

Reputation: 137

How to create watermark in textbox using silverlight?

Can someone explain to me how I could create a watermark in a textbox using silverlight?

Upvotes: 3

Views: 1707

Answers (3)

Josh Close
Josh Close

Reputation: 23383

I created a watermark TextBox and watermark PasswordBox.

It's available on NuGet: WindowsPhoneControls

You can look at the source here:

https://github.com/JoshClose/WindowsPhoneControls

Upvotes: 0

Oliver Weichhold
Oliver Weichhold

Reputation: 10296

<Grid x:Name="SearchPanel">
    <TextBox x:Name="txtQuery" Text="{Binding Query, Mode=TwoWay}" Margin="8" Padding="3, 3, 21, 3"
        GotFocus="txtQuery_GotFocus" LostFocus="txtQuery_LostFocus"/>

    <TextBlock x:Name="lblSearchStatus" VerticalAlignment="Center" Margin="13, 0"
        Text="Enter some text ..."
        IsHitTestVisible="False">
    </TextBlock>
</Grid>

Then hide lblSearchStatus in txtQuery_GotFocus and show it again in txtQuery_GotFocus. Could be also done via storyboard. The important part is setting IsHitTestVisible to false for the TextBlock overlay.

Upvotes: 0

Alireza Maddah
Alireza Maddah

Reputation: 5885

Here is what you need. http://watermarktextbox.codeplex.com/

enter image description here

Upvotes: 6

Related Questions