Back to Devexpress

PasswordBoxEdit Class

wpf-devexpress-dot-xpf-dot-editors-152bf3ac.md

latest8.7 KB
Original Source

PasswordBoxEdit Class

A control allowing you to enter and manage passwords.

Namespace : DevExpress.Xpf.Editors

Assembly : DevExpress.Xpf.Core.v25.2.dll

NuGet Package : DevExpress.Wpf.Core

Declaration

csharp
[DXLicenseWpfEditors]
public class PasswordBoxEdit :
    TextEditBase
vb
<DXLicenseWpfEditors>
Public Class PasswordBoxEdit
    Inherits TextEditBase

Remarks

The PasswordBoxEdit control allows you to hide the characters and optionally limit the password’s length.

Tip

The PasswordBoxEdit class inherits its features from the TextEditBase class.

Refer to the TextEditBase class description for information on derived features and API.

Create a PasswordBoxEdit

xaml
<Window ...
    xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors">

<dxe:PasswordBoxEdit 
    ShowCapsLockWarningToolTip="True"
    NullValue="" 
    NullText="Please enter your password..." />

Use the Password property to get a password entered by an end user.

Handle the BaseEdit.EditValueChanged event to get a notification when the editor’s value is changed. To validate the new value, handle the BaseEdit.Validate event.

Password Char

Use the PasswordChar property to specify any character that is masked in the password box.

CapsLock Warning

If the Caps Lock is turned on and the mouse pointer rests over the password box editor, the editor can display a warning tooltip. Set the ShowCapsLockWarningToolTip property to true to display the CapsLock warning tooltip.

To provide custom content for the warning tooltip, use the CapsLockWarningToolTipTemplate property.

Password Strength and Requirements

You can use the TextEditBase.MaxLength property to limit the length of a password typed by an end user.

The password strength is automatically estimated and returned by the PasswordStrength property. To manually estimate password strength, handle the CustomPasswordStrength event. The event parameter allows you to obtain the text currently entered by an end user (PasswordStrengthEventArgs.Password) and specify the password strength (PasswordStrengthEventArgs.PasswordStrength).

xaml
<dx:ThemedWindow ...
        xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
        xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
        dx:ThemeManager.Theme="Office2019Colorful">
    <Grid>
        <StackPanel Orientation="Horizontal" VerticalAlignment="Top">
            <dxe:PasswordBoxEdit x:Name="pwd" />
            <!-- Label content is bound to the PasswordBoxEdit's PasswordStrength property -->
            <Label Content="{DXBinding @e(pwd).PasswordStrength.ToString()}" Margin="10,0,0,0" />
        </StackPanel>
    </Grid>
</dx:ThemedWindow>

“Show Password” Button

Users can press and hold the “Show Password” button to display the concealed characters. Use the ShowPasswordButtonVisibility property to control the button’s visibility as follows:

PropertyDescription
NoneThe button is hidden.
AutoThe button is visible when the control’s value is not empty.
AlwaysThe button is visible.
xaml
<Window ...
    xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors">
    <StackPanel>
        <dxe:PasswordBoxEdit ShowPasswordButtonVisibility="Auto" />
    </StackPanel>
</Window>

The control’s edit box is read-only while you display the concealed password characters.

Show/Hide Password From Code

Call the ShowPassword()/HidePassword() to show/hide the PasswordBoxEdit‘s password programmatically.

Customize the “Show Password” Button

Use the ShowPasswordButtonTemplate property to specify the template for the “Show Password” button:

xaml
<Window ...
    xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors">
    <StackPanel>
        <dxe:PasswordBoxEdit ShowPasswordButtonVisibility="Auto">
            <dxe:PasswordBoxEdit.ShowPasswordButtonTemplate>
                <DataTemplate>
                    <TextBlock Text="Show Password" />
                </DataTemplate>
            </dxe:PasswordBoxEdit.ShowPasswordButtonTemplate>
        </dxe:PasswordBoxEdit>
    </StackPanel>
</Window>

Appearance Customization

Refer to the following topic for more information: Appearance Customization.

The following code snippets (auto-collected from DevExpress Examples) contain references to the PasswordBoxEdit class.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-richedit-document-encryption/CS/DXRichEdit_Encryption/MainWindow.xaml#L21

xml
VerticalContentAlignment="Center"/>
<dxe:PasswordBoxEdit x:Name="passwordEdit"
                     EditValueChanged="passwordChanged"

wpf-synchronous-theme-preload-with-splashscreen/CS/ThemePreloadwithSplashscreen/MainWindow.xaml#L17

xml
<dxe:TextEdit NullText="login" />
<dxe:PasswordBoxEdit Margin="0,10" NullText="password" />
<Button Width="50"

Inheritance

Object DispatcherObject DependencyObject Visual UIElement FrameworkElement Control BaseEdit TextEditBase PasswordBoxEdit

See Also

PasswordBoxEdit Members

PasswordBoxEditSettings

DevExpress.Xpf.Editors Namespace