如何将文本水印应用于xaml中的文本框(Windows 8 metro应用程序)

时间:2013-09-30 10:42:29

标签: c# xaml windows-8 winrt-xaml

我正在使用文本水印到Windows 8应用程序获取问题,有人可以帮我看看我们如何应用水印初始化。

下面的

是我的文本框的代码。

<TextBox x:Name="txtUserName" Width="351" Height="45" BorderBrush="Gray" BorderThickness="2" Background="{x:Null}"/>

4 个答案:

答案 0 :(得分:4)

使用

<TextBox Width="250" Name="_txtBox" PlaceholderText="Please enter CS#"/>

enter image description here

答案 1 :(得分:2)

你可以使用适用于Windows 8的Callisto工具包,它具有水印文本框控件。你可以从nuget包管理器安装它。 在页面中使用此命名空间..

xmlns:CallistoControls="using:Callisto.Controls"

像这样使用控件。

 <CallistoControls:WatermarkTextBox Watermark="Type to message"  HorizontalAlignment="Stretch" TextWrapping="Wrap" AcceptsReturn="True" MaxHeight="100"    Padding="5,5,20,30" />

还有其他有用的控件。希望这有助于你

答案 2 :(得分:0)

如果不使用第三方库或覆盖文本框并创建自己的“水印文本框”类,则无法执行此操作。您只需侦听已获得/失去的焦点事件并正确显示您的文本。

答案 3 :(得分:0)