Hi דני שטרית
Sure, you can use a combination of a PasswordBox
for entering the password and a CheckBox
for toggling the visibility of the password for this requirement you mentioned.
Xaml smippet here -
<Window x:Class="YourNamespace.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Password TextBox Demo" Height="300" Width="400"> <Grid> <StackPanel Margin="20"> <TextBlock Text="Enter Password:" FontWeight="Bold" Margin="0,0,0,5"/> <PasswordBox x:Name="passwordBox" Margin="0,0,0,10"/> <CheckBox Content="Show Password" x:Name="showPasswordCheckBox" Checked="ShowPassword_Checked" Unchecked="ShowPassword_Unchecked"/> </StackPanel> </Grid> </Window>
C# here
using System.Windows; namespace YourNamespace { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void ShowPassword_Checked(object sender, RoutedEventArgs e) { // When "Show Password" is checked, change PasswordBox's property to show the password passwordBox.PasswordChar = '\0'; } private void ShowPassword_Unchecked(object sender, RoutedEventArgs e) { // When "Show Password" is unchecked, change PasswordBox's property to hide the password passwordBox.PasswordChar = '●'; // You can use any character you prefer to represent hidden characters } } }
Try the above snippet and change it as per ur wish, hope it works.
If this helps kindly accept the answer thanks much.