Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
PasswordBox Class
Collapse the table of content
Expand the table of content

PasswordBox Class

Represents a control designed for entering and handling passwords.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

[TemplatePartAttribute(Name="PART_ContentHost", Type=typeof(FrameworkElement))] 
public sealed class PasswordBox : Control
/** @attribute TemplatePartAttribute(Name="PART_ContentHost", Type=System.Windows.FrameworkElement) */ 
public final class PasswordBox extends Control
TemplatePartAttribute(Name="PART_ContentHost", Type=System.Windows.FrameworkElement) 
public final class PasswordBox extends Control
<PasswordBox .../>


PasswordBox has built-in handling for the bubbling  MouseUp and MouseDown events. Consequently, custom event handlers that listen for MouseUp or MouseDown events from a PasswordBox will never be called. If you need to respond to these events, listen for the tunneling PreviewMouseUp and PreviewMouseDown events instead, or register the handlers with the HandledEventsToo argument (this latter option is only available through code). Do not mark the event handled unless you deliberately want to disable PasswordBox native handling of these events, and be aware that this has notable effects on the control's UI.

The following example shows how to specify the handler method for the PasswordChanged event.


The following example shows the corresponding event handler. In this case, the event handler simply increments a counter.

private int pwChanges = 0;

void PasswordChangedHandler(Object sender, RoutedEventArgs args)
    // Increment a counter each time the event fires.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

© 2015 Microsoft