--- title: "How to: Add a Watermark to a TextBox" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "displaying a background image inside a text box to aid user input [WPF]" - "aid usability of a TextBox using a background image [WPF]" ms.assetid: df89bdd8-a0fb-45e0-b312-dd53332d01a8 --- # How to: Add a Watermark to a TextBox The following example shows how to aid usability of a by displaying an explanatory background image inside of the 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](./media/editing-textbox-using-background-image.png "Editing_TextBox_using_background_image") > [!NOTE] > The reason a background image is used in this example rather then simply manipulating the property of , is that a background image will not interfere with data binding. ## Example [!code-xaml[TextBoxMiscSnippets_snip#TextBoxBackgroundExampleWholePage](~/samples/snippets/csharp/VS_Snippets_Wpf/TextBoxMiscSnippets_snip/csharp/textbox_with_background_image.xaml#textboxbackgroundexamplewholepage)] [!code-csharp[TextBoxMiscSnippets_snip#TextBoxBackgroundCodeExampleWholePage](~/samples/snippets/csharp/VS_Snippets_Wpf/TextBoxMiscSnippets_snip/csharp/textbox_with_background_image.xaml.cs#textboxbackgroundcodeexamplewholepage)] [!code-vb[TextBoxMiscSnippets_snip#TextBoxBackgroundCodeExampleWholePage](~/samples/snippets/visualbasic/VS_Snippets_Wpf/TextBoxMiscSnippets_snip/visualbasic/textbox_with_background_image.xaml.vb#textboxbackgroundcodeexamplewholepage)] ## See also - [TextBox Overview](textbox-overview.md) - [RichTextBox Overview](richtextbox-overview.md)