如何将水印文本添加到 wpf 中的文本框? [英] How can I add watermark text to a textbox in wpf?
本文介绍了如何将水印文本添加到 wpf 中的文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个 wpf 应用程序.如何将水印文本添加到 textbox
和 passwordbox
?
Im working on a wpf application.How I can add watermark text to the textbox
and passwordbox
?
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Platforma Smart School 1.0" Height="580" Width="880"
Icon="/WpfApplication4;component/Images/capturennnnnn12_256px%20%282%291.ico">
<Grid>
<Grid.Background>
<ImageBrush ImageSource="/WpfApplication1;component/Images/
hp-colorful-books-hd-105609.jpg" />
</Grid.Background>
<Rectangle Height="334" HorizontalAlignment="Left" Margin="608,162,0,0"
Name="rectangle1" Stroke="#FFDBD8D8" VerticalAlignment="Top" Width="222"
Fill="#FFF0F0F0" />
<Button Height="34" HorizontalAlignment="Left" Margin="630,434,0,0"
Name="button1" VerticalAlignment="Top" Width="178" FontSize="13"
Foreground="#FF555555" />
<TextBox Height="34" HorizontalAlignment="Left" Margin="630,219,0,0"
Name="textBox1" VerticalAlignment="Top" Width="178" FontSize="14" Text=""
Foreground="#FF7C7A7A" />
<PasswordBox Height="32" HorizontalAlignment="Left" Margin="630,304,0,0"
Name="passwordBox1" VerticalAlignment="Top" Width="178" FontSize="14"
FontFamily="Segoe UI"/>
<Image Height="134" HorizontalAlignment="Left" Margin="606,12,0,0"
Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="224"
Source="/WpfApplication1;component/Images/Capture3.PNG" />
<Label Content=" Smart School" Height="31" HorizontalAlignment="Left"
Margin="251,498,0,0" Name="label1" VerticalAlignment="Top" Width="227" />
</Grid>
推荐答案
看看这个 SO 问题.创建附加属性的第二个答案是我的建议.
Take a look at this SO Question. The second answer of creating an Attached Property is what I would suggest.
还有一些扩展的 WPF 控件可以提供帮助:http://wpftoolkit.codeplex.com/wikipage?title=WatermarkTextBox
There are also some extended WPF controls that can help: http://wpftoolkit.codeplex.com/wikipage?title=WatermarkTextBox
添加了扩展的 WPF 工具包链接.
Added Extended WPF Toolkit link.
这篇关于如何将水印文本添加到 wpf 中的文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文