Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8740141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:04:45+00:00 2026-06-13T11:04:45+00:00

Possible Duplicate: Watermark TextBox in WPF May i know how to put some default

  • 0

Possible Duplicate:
Watermark TextBox in WPF

May i know how to put some default texts in the password box in WPF?
I use MSN messenger as an example. When its default, the password field will show the “password” in the Password Box. When i click and type on the password box, the “password” text will disappear and the dots will replace it.

enter image description here

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:04:46+00:00Added an answer on June 13, 2026 at 11:04 am

    You have to create a custom control to do that.

    XAML:

    <Window x:Class="WpfTest.Window1" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:WpfTest="clr-namespace:WpfTest" 
        Title="Password Box Sample" Height="300" Width="300"> 
      <Window.Resources> 
        <Style x:Key="{x:Type PasswordBox}" 
            TargetType="{x:Type PasswordBox}"> 
          <Setter Property="WpfTest:PasswordBoxMonitor.IsMonitoring" 
                  Value="True"/> 
          <Setter Property="Template"> 
            <Setter.Value> 
              <ControlTemplate TargetType="{x:Type PasswordBox}"> 
                <Border Name="Bd" 
                        Background="{TemplateBinding Background}" 
                        BorderThickness="{TemplateBinding BorderThickness}" 
                        BorderBrush="{TemplateBinding BorderBrush}" 
                        SnapsToDevicePixels="true"> 
                  <Grid> 
                    <ScrollViewer x:Name="PART_ContentHost" 
                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 
                    <TextBlock Text="Please enter your password"  
                               Margin="4, 2, 0, 0" 
                               Foreground="Gray"  
                               Visibility="Collapsed" 
                               Name="txtPrompt" /> 
                  </Grid> 
                </Border> 
                <ControlTemplate.Triggers> 
                  <Trigger Property="IsEnabled" 
                                                                             Value="false"> 
                    <Setter TargetName="Bd" 
                                                                                    Property="Background" 
                                                                                    Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> 
                    <Setter Property="Foreground" 
                                                                                    Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 
                  </Trigger> 
                  <Trigger Property="WpfTest:PasswordBoxMonitor.PasswordLength" Value="0"> 
                    <Setter Property="Visibility" TargetName="txtPrompt" Value="Visible"/> 
                  </Trigger> 
                </ControlTemplate.Triggers> 
              </ControlTemplate> 
            </Setter.Value> 
          </Setter> 
        </Style> 
      </Window.Resources> 
      <Grid> 
        <PasswordBox VerticalAlignment="Top"/> 
      </Grid> 
    </Window> 
    

    C# code:

    using System.Windows; 
    using System.Windows.Controls; 
    
    namespace WpfTest 
    { 
        public partial class Window1 : Window 
        { 
            public Window1() 
            { 
                    InitializeComponent(); 
            } 
    
        } 
    
      public class PasswordBoxMonitor : DependencyObject 
      { 
        public static bool GetIsMonitoring(DependencyObject obj) 
        { 
          return (bool)obj.GetValue(IsMonitoringProperty); 
        } 
    
        public static void SetIsMonitoring(DependencyObject obj, bool value) 
        { 
          obj.SetValue(IsMonitoringProperty, value); 
        } 
    
        public static readonly DependencyProperty IsMonitoringProperty = 
            DependencyProperty.RegisterAttached("IsMonitoring", typeof(bool), typeof(PasswordBoxMonitor), new UIPropertyMetadata(false, OnIsMonitoringChanged)); 
    
    
    
        public static int GetPasswordLength(DependencyObject obj) 
        { 
          return (int)obj.GetValue(PasswordLengthProperty); 
        } 
    
        public static void SetPasswordLength(DependencyObject obj, int value) 
        { 
          obj.SetValue(PasswordLengthProperty, value); 
        } 
    
        public static readonly DependencyProperty PasswordLengthProperty = 
            DependencyProperty.RegisterAttached("PasswordLength", typeof(int), typeof(PasswordBoxMonitor), new UIPropertyMetadata(0)); 
    
        private static void OnIsMonitoringChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
        { 
          var pb = d as PasswordBox; 
          if (pb == null) 
          { 
            return; 
          } 
          if ((bool) e.NewValue) 
          { 
            pb.PasswordChanged += PasswordChanged; 
          } 
          else 
          { 
            pb.PasswordChanged -= PasswordChanged; 
          } 
        } 
    
        static void PasswordChanged(object sender, RoutedEventArgs e) 
        { 
          var pb = sender as PasswordBox; 
          if (pb == null) 
          { 
            return; 
          } 
          SetPasswordLength(pb, pb.Password.Length); 
        } 
      } 
    } 
    

    Reference: WPF Watermark PasswordBox from Watermark TextBox

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What does jQuery.fn mean? I have some script on a page trying
Possible Duplicate: C# driver development? I would like to know if I can do
Possible Duplicate: Arithmetic in ruby The status_update model takes 2 values in, does some
Possible Duplicate: Watermarked Textbox for Compact Framework Using Visual Studio 2008 SP1, the latest
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: Place watermark image on other images (C#, ASP.Net) how to add water
Possible Duplicate: Why do I see a double variable initialized to some value like
Possible Duplicate: Fix for Xcode's indiscernible highlighting of inline errors? Does anyone know how
Possible Duplicate: Variable setting in Dreamweaver template in SDL Tridion We use RenderComponentPresentation (on
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.