title: PasswordBox Hint Text in WPF
body: <p>I wrote a PasswordBox style.I want to do hint text in passwordbox but when the lost focus ,the hint text is appering.Where I'm doing mistake, How can I solve this problem?</p>
  
  <p>Here is code:</p>
  
  <pre><code> &lt;Style TargetType="{x:Type PasswordBox}"  xmlns:sys="clr-namespace:System;assembly=mscorlib"&gt;
      &lt;Style.Resources&gt;
          &lt;VisualBrush  x:Key="Bg1" AlignmentX="Center" AlignmentY="Center" Stretch="None" &gt;
              &lt;VisualBrush.Visual&gt;
                  &lt;Label Content="Enter password" Foreground="LightGray" Margin="5,0,0,0"/&gt;
              &lt;/VisualBrush.Visual&gt;
          &lt;/VisualBrush&gt;
          &lt;VisualBrush  x:Key="Bg2" AlignmentX="Center" AlignmentY="Center" Stretch="None" &gt;
              &lt;VisualBrush.Visual&gt;
                  &lt;Label Content="" Foreground="LightGray" Margin="5,0,0,0"/&gt;
              &lt;/VisualBrush.Visual&gt;
          &lt;/VisualBrush&gt;
      &lt;/Style.Resources&gt;
      &lt;Setter Property="FontSize" Value="16"/&gt;
      &lt;Setter Property="Foreground" Value="#FF585858"/&gt;
      &lt;Setter Property="VerticalContentAlignment" Value="Center"/&gt;
      &lt;Setter Property="HorizontalContentAlignment" Value="Center"/&gt;
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="{x:Type PasswordBox}"&gt;
                  &lt;Border CornerRadius="2" x:Name="border" Background="{TemplateBinding Background}" BorderThickness="1" BorderBrush="LightGray"&gt;
                      &lt;ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Visible" Margin="0" ScrollViewer.CanContentScroll="True" x:Name="PART_ContentHost"/&gt;
                  &lt;/Border&gt;
                  &lt;ControlTemplate.Triggers&gt;
                      &lt;Trigger Property="IsFocused" Value="True"&gt;
                          &lt;Setter Property="BorderBrush" TargetName="border" Value="#FFD0D0D0"/&gt;
                          &lt;Setter Property="BorderThickness" TargetName="border" Value="2"/&gt;
                      &lt;/Trigger&gt;
  
                      &lt;DataTrigger Binding="{Binding Path=Password}" Value="{x:Static sys:String.Empty}"&gt;
                          &lt;Setter Property="Background" Value="{StaticResource Bg2}" /&gt;
                      &lt;/DataTrigger&gt;
  
                      &lt;DataTrigger Binding="{Binding Path=Password}" Value="{x:Null}"&gt;
                          &lt;Setter Property="Background" Value="{StaticResource Bg1}" /&gt;
                      &lt;/DataTrigger&gt;                      
  
                      &lt;Trigger Property="IsKeyboardFocused" Value="True"&gt;
                          &lt;Setter Property="Background" Value="White" /&gt;
                      &lt;/Trigger&gt;                      
  
                  &lt;/ControlTemplate.Triggers&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;   
  </code></pre>
  
  <p>Thanks for your advice.</p>