title | page_title | description | slug | tags | published | position |
---|---|---|---|---|---|---|
Getting Started |
Getting Started |
Check our "Getting Started" documentation article for the RadPasswordBox {{ site.framework_name }} control. |
radpasswordbox-getting-started |
getting,started |
true |
1 |
This tutorial will walk you through the creation of a sample application that contains RadPasswordBox.
- Adding Telerik Assemblies Using NuGet
- Adding Assembly References Manually
- Adding RadPasswordBox to the Project
- Setting Watermark
To use RadPasswordBox when working with NuGet packages, install the Telerik.Windows.Controls.for.Wpf.Xaml
package. The [package name may vary]({%slug nuget-available-packages%}) slightly based on the Telerik dlls set - [Xaml or NoXaml]({%slug xaml-vs-noxaml%})
Read more about NuGet installation in the [Installing UI for WPF from NuGet Package]({%slug nuget-installation%}) article.
tip With the 2025 Q1 release, the Telerik UI for WPF has a new licensing mechanism. You can learn more about it [here]({%slug installing-license-key%}).
If you are not using NuGet packages, you can add a reference to the following assemblies:
- Telerik.Licensing.Runtime
- Telerik.Windows.Controls
Before proceeding with adding RadPasswordBox to your project, make sure the required assembly references are added to the project.
You can add RadPasswordBox manually by writing the XAML code in Example 1. You can also add the control by dragging it from the Visual Studio Toolbox and dropping it over the XAML view.
{{region passwordbox-getting-started_0}} <telerik:RadPasswordBox Width="150" /> {{endregion}}
In order to use RadPasswordBox in XAML you have to add the namespace declaration shown in Example 2:
{{region telerik-schemas}} xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" {{endregion}}
If you run the application you will see the PasswordBox as illustrated in Figure 1.
When RadPasswordBox is empty and not focused, Watermark content can be shown. Example 2 demonstrates how to set Watermark text.
{{region passwordbox-getting-started_1}} <telerik:RadPasswordBox Width="150" WatermarkContent="enter a password" /> {{endregion}}
Figure 2 shows the result.
The Text property of the RadPasswordBox contains only the sequence of masking characters set by the PasswordChar property. The actual input can be reached through the Password and SecurePassword properties. These properties are not dependency properties (cannot be bound) due to security reasons. To get these properties in MVVM, you can pass the RadPasswordBox element to a command from your view model. Let's demonstrate this with some code.
First we will declare the RadPasswordBox in XAML and bind a RadButton's Command property to a command from our view model.
{{region passwordbox-getting-started_2}} <telerik:RadPasswordBox x:Name="passwordBox" WatermarkContent="enter a password" Width="150" Margin="0 0 10 0" /> <telerik:RadButton Content="Log in" Command="{Binding LoginCommand}" CommandParameter="{Binding ElementName=passwordBox}"/> {{endregion}}
Now we just need to create our view model.
{{region passwordbox-getting-started_2}} public class ViewModel { public System.Windows.Input.ICommand LoginCommand { get; set; } public ViewModel() { LoginCommand = new DelegateCommand(OnLoginCommand_Executed); }
private void OnLoginCommand_Executed(object obj)
{
var passwordBox = obj as RadPasswordBox;
if(passwordBox != null)
{
// actual entered password
var password = passwordBox.Password;
}
}
}
{{endregion}}
Voilà! Now when you click on the Login button, the LoginCommand.Execute() method will be called. Inside the method you can get the RadPasswordBox from the parameter and see the entered password from the Password property.
The controls from our suite support different themes. You can see how to apply a theme different than the default one in the [Setting a Theme]({%slug styling-apperance-implicit-styles-overview%}) help article.
important Changing the theme using implicit styles will affect all controls that have styles defined in the merged resource dictionaries. This is applicable only for the controls in the scope in which the resources are merged.
To change the theme, you can follow the steps below:
-
Choose between the themes and add reference to the corresponding theme assembly (ex: Telerik.Windows.Themes.Windows8.dll). You can see the different themes applied in the Theming examples from our {% if site.site_name == 'WPF' %}WPF Controls Examples{% else %}Silverlight Controls Examples{% endif %} application.
-
Merge the ResourceDictionaries with the namespace required for the controls that you are using from the theme assembly. For the RadPasswordBox, you will need to merge the following resources:
- Telerik.Windows.Controls
- Telerik.Windows.Controls.Navigation
Example 4 demonstrates how to merge the ResourceDictionaries so that they are applied globally for the entire application.
{{region radpasswordbox-getting-started_4}} <Application.Resources> <ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries> </Application.Resources> {{endregion}}
Alternatively, you can use the theme of the control via the {% if site.site_name == 'WPF' %}StyleManager{% else %}StyleManager{% endif %}.
Figure 2 shows a RadPasswordBox with the Windows8 theme applied.
{% if site.site_name == 'WPF' %}
- Telerik UI for WPF PasswordBox Component
- [Getting Started with Telerik UI for WPF Components]({%slug getting-started-first-steps%})
- [Telerik UI for WPF Installation]({%slug installation-installing-which-file-do-i-need%})
- [Telerik UI for WPF and WinForms Integration]({%slug winforms-integration%})
- [Telerik UI for WPF Visual Studio Templates]({%slug visual-studio-templates%})
- [Setting a Theme with Telerik UI for WPF]({%slug styling-apperance-implicit-styles-overview%})
- Telerik UI for WPF Virtual Classroom (Training Courses for Registered Users)
- Telerik UI for WPF License Agreement {% endif %}
-
[Overview]({%slug radpasswordbox-overview%})
-
[Visual Structure]({%slug radpasswordbox-visual-structure%})