如何使用Silverlight在文本框中创建水印?

问题描述

| 有人可以向我解释如何使用Silverlight在文本框中创建水印吗?     

解决方法

这就是您所需要的。 http://watermarktextbox.codeplex.com/     ,
<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>
然后将lblSearchStatus隐藏在txtQuery_GotFocus中,并再次在txtQuery_GotFocus中显示。也可以通过情节提要来完成。重要的是将TextBlock叠加层的IsHitTestVisible设置为false。     ,我创建了一个水印TextBox和一个水印PasswordBox。 在NuGet上可用:WindowsPhoneControls 您可以在此处查看源代码: https://github.com/JoshClose/WindowsPhoneControls