Files
docs-desktop/dotnet-desktop-guide/framework/wpf/controls/how-to-add-a-watermark-to-a-textbox.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

1.9 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Add a Watermark to a TextBox 03/30/2017
csharp
vb
displaying a background image inside a text box to aid user input [WPF]
aid usability of a TextBox using a background image [WPF]
df89bdd8-a0fb-45e0-b312-dd53332d01a8

How to: Add a Watermark to a TextBox

The following example shows how to aid usability of a xref:System.Windows.Controls.TextBox by displaying an explanatory background image inside of the xref:System.Windows.Controls.TextBox until the user inputs text, at which point the image is removed. In addition, the background image is restored again if the user removes their input. See illustration below.

A TextBox with a background image

Note

The reason a background image is used in this example rather then simply manipulating the xref:System.Windows.Controls.TextBox.Text%2A property of xref:System.Windows.Controls.TextBox, is that a background image will not interfere with data binding.

Example

[!code-xamlTextBoxMiscSnippets_snip#TextBoxBackgroundExampleWholePage]

[!code-csharpTextBoxMiscSnippets_snip#TextBoxBackgroundCodeExampleWholePage] [!code-vbTextBoxMiscSnippets_snip#TextBoxBackgroundCodeExampleWholePage]

See also