This documentation is archived and is not being maintained.

PasswordBox Class

Represents a control designed for entering and handling passwords.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:

<TemplatePartAttribute(Name:="PART_ContentHost", Type:=GetType(FrameworkElement))> _
Public NotInheritable Class PasswordBox
	Inherits Control
Dim instance As PasswordBox

/** @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