Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I cannot see whole template but this looks a bit overcomplicated. I assume you're trying to achieve watermark text. For hint use box standard <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.tooltip.aspx" rel="nofollow"><code>ToolTip</code></a> property, which by default will display your text in a popup when hover your <code>TextBox</code> but this behaviour can be disabled and <code>ToolTip</code> property reused. You can either create reusable <code>Style</code> - which I prefer - for <code>TextBox</code>, something like this:</p> <pre><code>&lt;Window ...&gt; &lt;Window.Resources&gt; &lt;BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/&gt; &lt;Style TargetType="{x:Type TextBox}" x:Key="WatermarkTextBoxStyle"&gt; &lt;Setter Property="ToolTipService.IsEnabled" Value="False"/&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type TextBox}"&gt; &lt;Border Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" BorderThickness="1" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}"&gt; &lt;Grid&gt; &lt;TextBlock Margin="5,0,0,0" Text="{TemplateBinding ToolTip}" Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Text.IsEmpty, Converter={StaticResource BooleanToVisibilityConverter}}" Opacity="0.5"/&gt; &lt;ScrollViewer Name="PART_ContentHost"/&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/Window.Resources&gt; &lt;TextBox ToolTip="watermark text" Style="{StaticResource WatermarkTextBoxStyle}"/&gt; &lt;/Window&gt; </code></pre> <p>or, if it's a one-off thing, then do you can do something like this without any <code>Style</code> or <code>Template</code>:</p> <pre><code>&lt;Grid Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"&gt; &lt;TextBlock Margin="5,0,0,0" Text="watermark text" Opacity="0.5" Visibility="{Binding ElementName=myTextBox, Path=Text.IsEmpty, Converter={StaticResource BooleanToVisibilityConverter}}" /&gt; &lt;TextBox Name="myTextBox" Background="Transparent" /&gt; &lt;/Grid&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload