![]() This.SetValue(BoundPassWordProperty, pwd.Password) Private void Pwd_PasswordChanged(object sender, RoutedEventArgs e) Pwd.PasswordChanged += Pwd_PasswordChanged This.SetBinding(BoundPassWordProperty, new Binding("ViewModelPassword")) Public static readonly DependencyProperty BoundPassWordProperty =ĭependencyProperty.Register("BoundPassWord", typeof(string) Here's a start: Īnd public partial class LogInWindow : Window I suggest you consider refactoring into a window or usercontrol. Focussing on the passwordbox is a mistake, IMO. The passwordbox is going to go in a window or usercontrol which is all about logging in. This is looking at the small picture though. Passwordbox password#XAML Guy's styling is an elegant solution to putting a watermark on a password box. The password helper attached property is an elegant solution to binding the password. When I run the app I want to log in with my user name and password, only a valid user name and password should let me use the app. How many password boxes are you going to have in an app? Private void pwd_LostFocus(object sender, RoutedEventArgs e) Private void TextBox_GotFocus(object sender, RoutedEventArgs e) Īnd public partial class MainWindow : Window do you really want the watermark to re-appear?Īnyhow, you could overlay it with a textbox and do this with some events. Once they're entered their password and tab away. I think this is the hard way to do watermarks. Please don't ask several questions in the same thread. Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Passwordbox code#You can download or browse the complete sample code here: This works provided that you add a reference to (Project->Add Reference->Assemblies->Framework): You need to modify the ControlTemplate of the PasswordBox for the value of the attached property to actually be displayed. Passwordbox how to#XAML Guy has provided an example of how to implement a watermarked PasswordBox in the code gallery that you could refer to: Otherwise it is equal to false then get the watermark When passwordbox has focus is equal to true then remove the watermark Pwd.PasswordChanged -= new RoutedEventHandler(pwd_PasswordChanged) Static void pwd_Unloaded(object sender, RoutedEventArgs e) Static void pwd_PasswordChanged(object sender, RoutedEventArgs e) Pwd.SetValue(PasswordBoxHelper.ShowWatermarkProperty, pwd.Password = string.Empty) Private static void CheckShowWatermark(PasswordBox pwd) Pwd.Unloaded += new RoutedEventHandler(pwd_Unloaded) Pwd.PasswordChanged += new RoutedEventHandler(pwd_PasswordChanged) Static void WatermarkChanged(DependencyObject obj, DependencyPropert圜hangedEventArgs e) Public static readonly DependencyProperty ShowWatermarkProperty =ĭependencyProperty.RegisterAttached("ShowWatermark", typeof(bool), typeof(PasswordBoxHelper), new UIPropertyMetadata(false)) Obj.SetValue(ShowWatermarkProperty, value) Public static void SetShowWatermark(DependencyObject obj, bool value) Return (bool)obj.GetValue(ShowWatermarkProperty) Public static bool GetShowWatermark(DependencyObject obj) Public static readonly DependencyProperty WatermarkProperty =ĭependencyProperty.RegisterAttached("Watermark", typeof(string), typeof(PasswordBoxHelper), new UIPropertyMetadata(null, WatermarkChanged)) Public static void SetWatermark(DependencyObject obj, string value) Return (string)obj.GetValue(WatermarkProperty) Public static string GetWatermark(DependencyObject obj) ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |