title: WPF PasswordBox label visibility
body: <p>I have created a passwordbox user control for a login screen. I was trying to use a watermark approach, but most of the examples I saw failed when I tried to use them. I switched to just being able to manipulate the label's visibility through c# code.</p>
  
  <pre><code>&lt;Style x:Key="{x:Type PasswordBox}"
         x:Name="Style1"
         BasedOn="{StaticResource {x:Type PasswordBox}}"
         TargetType="{x:Type PasswordBox}"&gt;
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="{x:Type PasswordBox}"&gt;
                  &lt;Border x:Name="TextBoxBorder" 
                          BorderBrush="{TemplateBinding BorderBrush}" 
                          BorderThickness="{TemplateBinding BorderThickness}"
                          CornerRadius="7"&gt;
                      &lt;Border.Background&gt;
                           &lt;LinearGradientBrush StartPoint="0,0" EndPoint="2,1"&gt;
                                &lt;GradientStop Color="{Binding Path=GradientColorStart}" 
                                              Offset="0"/&gt;
                                &lt;GradientStop Color="{Binding Path=GradientColorEnd}" 
                                              Offset="1"/&gt;
                           &lt;/LinearGradientBrush&gt;
                      &lt;/Border.Background&gt;
                      &lt;Grid&gt;
                          &lt;Label x:Name="TextPrompt" 
                                 Content="Password" 
                                 Focusable="False" 
                                 FontSize="15"
                                 Foreground="Green"
                                 Visibility="Visible" /&gt;
                          &lt;ScrollViewer x:Name="PART_ContentHost"  Margin="0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /&gt;
                      &lt;/Grid&gt; 
                   &lt;/Border&gt;
                   &lt;ControlTemplate.Triggers&gt;
                       &lt;Trigger Property="IsFocused" Value="True"&gt;
                           &lt;Setter Property="Foreground"
                                   Value="{Binding Path=OnFocusTextColor}" /&gt;
                           &lt;Setter Property="FontWeight"
                                   Value="{Binding Path=OnFocusFontWeight}" /&gt;
                           &lt;Setter Property="FontStyle"
                                   Value="{Binding Path=OnFocusFontStyle}" /&gt;
                      &lt;/Trigger&gt;
                  &lt;/ControlTemplate.Triggers&gt;
              &lt;!--
                  &lt;ControlTemplate.Triggers&gt;
                      &lt;MultiTrigger&gt;
                          &lt;MultiTrigger.Conditions&gt;
                              &lt;Condition Property="IsFocused" Value="False"/&gt;
                              &lt;Condition Property="Password" Value=""/&gt;
                          &lt;/MultiTrigger.Conditions&gt;
                          &lt;Setter Property="Visibility"
                                  TargetName="TextPrompt
                                  Value="Visible"/&gt;
                      &lt;/MultiTrigger&gt;
                      &lt;Trigger Property="IsFocused" Value="True"&gt;
                          &lt;Setter Property="Foreground" Value="{Binding Path=OnFocusTextColor}" /&gt;
                          &lt;Setter Property="FontWeight" Value="{Binding Path=OnFocusFontWeight}" /&gt;
                          &lt;Setter Property="FontStyle" Value="{Binding Path=OnFocusFontStyle}" /&gt;
                      &lt;/Trigger&gt;
                      &lt;Trigger Property="IsEnabled" Value="False"&gt;
                          &lt;Setter Property="Foreground" Value="DimGray" /&gt;
                      &lt;/Trigger&gt; 
                  &lt;/ControlTemplate.Triggers&gt;
               --&gt;
              &lt;/ControlTemplate&gt; 
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  </code></pre>
  
  <p>Code for the control</p>
  
  <pre><code>&lt;PasswordBox x:Name="PasswordTest"
      FontSize="15"
      Padding="{Binding Path=TextPadding}"
      Tag="{Binding Path=TextValue}"
      PasswordChanged="PasswordTest_PasswordChanged"&gt;
  &lt;/PasswordBox&gt;
  </code></pre>
  
  <p>C# for <code>PasswordTest_PasswordChanged</code></p>
  
  <pre><code>private void PasswordTest_PasswordChanged(object sender, RoutedEventArgs e)
  {
  
  }
  </code></pre>
  
  <p>I tried accessing the label but not sure how to exactly. I tried parsing the sender as a passwordbox like other examples use for watermarks, but I am unable to access the password attribute.</p>