<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ben Dewey - Web, XAML, and Cloud &#187; WPF Controls</title>
	<atom:link href="http://www.bendewey.com/index.php/tag/wpf-controls/feed" rel="self" type="application/rss+xml" />
	<link>http://www.bendewey.com</link>
	<description>Father, Developer, Microsoft MVP, Speaker, and Author</description>
	<lastBuildDate>Sat, 22 Mar 2025 05:04:02 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.8.41</generator>
	<item>
		<title>WPF Shadowed TextBox (aka. WPF Watermark TextBox)</title>
		<link>http://www.bendewey.com/index.php/12/wpf-shadowed-textbox-watermark</link>
		<comments>http://www.bendewey.com/index.php/12/wpf-shadowed-textbox-watermark#comments</comments>
		<pubDate>Sun, 28 Sep 2008 03:59:26 +0000</pubDate>
		<dc:creator><![CDATA[bendewey]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[WPF Controls]]></category>

		<guid isPermaLink="false">http://bendewey.wordpress.com/?p=12</guid>
		<description><![CDATA[This article demonstrates a Shadowed TextBox in WPF.  The initial concept seemed like it would be easy.  I went through about 3 different iterations in order.]]></description>
				<content:encoded><![CDATA[<p>This article demonstrates a Shadowed TextBox in WPF.  The initial concept seemed like it would be easy.  I went through about 3 different iterations in order to tackle this situation.  The first two had potential, but both had odd issues that forced me to try different techniques.  The winning solution uses an adorner to decorate the Textbox with a label.</p>
<h2>Failed Techniques</h2>
<h3>Change the Text and Style on Got/Lost Focus</h3>
<p>In this technique I would just  change the Text of the Textbox and and the Style whenever the TextBox Got or Lost Focus.  I had used this technique previously in WinForms, but this App that I was building used Drag-and-Drop in the textboxes and the users had expressed the need for this feature.  The issues with Drag-and-Drop using this technique were a nightmare.  This on top of other issues such as Binding caused be to abandon this technique.</p>
<h3>Changing the Textboxes Background to a VisualBrush with with a Label</h3>
<p>In this technique I would change the background of the TextBox to a VisualBrush that contained a Label on Got/Lost Focus.  This method had some initial pitfalls and work arounds with sizing.  I finally got past that by setting the VisualBrush Stretch=None.  This technique worked great until I went to my DataBound Form.  If a textbox has a value with one record, when you changed records that textboxes background wouldn&#8217;t update.  I searched a long time for a method to override to force that update, but no luck.</p>
<h2>Winning Technique</h2>
<h3>Textbox adorned by a Label</h3>
<p>View Code Preview:  <a title="View the ShadowedTextBox.cs File" href="http://www.bendewey.com/code/ShadowedTextBox.html" target="_blank">ShadowedTextBox.cs</a><br />
Download Source Code: <a title="Download Solution for ShadowedTextBoxExample (70.3 KB)" href="http://www.bendewey.com/code/ShadowedTextBoxExample.zip" target="_blank">ShadowedTextBoxExample.zip (70.3 KB)</a></p>
<div class="mceTemp">
<dl class="wp-caption alignleft">
<dt class="wp-caption-dt"><a href="http://bendewey.files.wordpress.com/2008/09/shadowedtextbox.gif"><img class="size-full wp-image-15" title="shadowedtextbox" src="http://bendewey.files.wordpress.com/2008/09/shadowedtextbox.gif" alt="Shadowed TextBox Preview" width="277" height="80" /></a></dt>
<dd class="wp-caption-dd">Shadowed TextBox Preview</dd>
</dl>
<p>This final technique worked great and involves creating and attaching an <a title="Code Preview of the AdornerLabel.cs File" href="http://www.bendewey.com/code/AdornerLabel.html" target="_blank">AdornerLabel</a> to the TextBox.  This version worked with styling, drag-drop, and Binding, right out of the box.  All you need to do to get the Shadowed TextBox working is add the required files and set the Label and LabelStyle of the <a title="View the ShadowedTextBox Code Preview Page" href="http://www.bendewey.com/code/ShadowedTextBox.html" target="_blank">ShadowedTextBox</a>.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.bendewey.com/index.php/12/wpf-shadowed-textbox-watermark/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
