Partilhar via


PasswordBox.Password Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets the password currently held by the PasswordBox.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Property Password As String
public string Password { get; set; }
<PasswordBox Password="string"/>

Property Value

Type: System.String
A string representing the password currently held by the PasswordBox.
The default value is Empty.

Exceptions

Exception Condition
ArgumentNullException

The property is set to a nulla null reference (Nothing in Visual Basic) value.

Remarks

Setting this property to a nulla null reference (Nothing in Visual Basic) reference (Nothing in Visual Basic) causes the underlying password to be set to Empty.

Examples

The following code snippet sets the password to "HelloWorld" using the Password property. This example is part of a larger example available in the PasswordBox class overview.

Security noteSecurity Note:

Avoid hard-coding a password within your source code.

<TextBlock Text="PasswordChar demonstration" Margin="20,10,0,0"/>
<PasswordBox x:Name="MyPWBox2" Margin="20,10,0,0" Height="35" Width="200" Password="HelloWorld" HorizontalAlignment="Left"/>
<PasswordBox x:Name="MyPWBox3" Margin="20,10,0,0" Height="35" Width="200" Password="HelloWorld" PasswordChar="$" HorizontalAlignment="Left"/>

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.