#WPF PASSWORDBOX HIDES TEXT PASSWORD#I had this exact requirement two weeks ago and I had to solve it, so this blog talks about the approach I took to make this happen.īasically all I needed to do was to switch from using password boxes to normal textbox and then wire the key up event in the background to hide the entered password. As a consequence, you cannot do many of the things that you normally do with a textbox such as customising the appearance of the password textbox (say you want to make the text centre-aligned, or you want to bind the number keypad instead of the alpha keyboard). #WPF PASSWORDBOX HIDES TEXT WINDOWS#The ToolTip is created only once together with the password window.In Windows XAML world, a bad design decision was made to have PasswordBox and TextBox as different objects, meaning that the PasswordBox does not inherit common properties from the TextBox. Of course, we will still work on the design it's worth working on :) and it's better to have such a special one. PasswordBox.ToolTip = tooltip //установка Yes, a crutch, but this is the simplest solution.Ī link to a very similar answer from the big SO: showing password characters on some event for passwordbox you can also add Focus, as done there.Īs noted above, although PasswordBox does not have such functionality directly, (!)but it is possible to implement several crutcher solution through the PasswordBox's own popup hint, which is an object (and not just a line) - we will create a, we will configure it and after installing/resetting the checkmark in the checkbox, we will fill in/clear the PasswordBox hint, for example:: private void checkBox_Click(object sender, RoutedEventArgs e)//на установку/снятие галочки Var passrod = ? pwdTextBox.Text : pwdPasswordBox.Password Well, by clicking on the button, we will display our password, this is for clarity: private void Button_Click_1(object sender, RoutedEventArgs e) PwdPasswordBox.Visibility = Visibility.Visible // PasswordBox - отобразить PwdTextBox.Visibility = Visibility.Hidden // TextBox - скрыть PwdPasswordBox.Password = pwdTextBox.Text // скопируем в PasswordBox из TextBox PwdPasswordBox.Visibility = Visibility.Hidden // PasswordBox - скрыть PwdTextBox.Visibility = Visibility.Visible // TextBox - отобразить PwdTextBox.Text = pwdPasswordBox.Password // скопируем в TextBox из PasswordBox The handler for a click on CheckBox will be like this: private void CheckBox_Click(object sender, RoutedEventArgs e) The main condition is the location of TextBox and PasswordBox in the same place with the same coordinates.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |