villasg.blogg.se

Wpf passwordbox watermark
Wpf passwordbox watermark






/ Class that provides the Watermark attached property Here is the source for the Attached Property: using System You can create a watermark that can be added to any TextBox with an Attached Property. Please notice PasswordBoxMonitor in XAML code. SetPasswordLength(pb, pb.Password.Length)

wpf passwordbox watermark

Static void PasswordChanged(object sender, RoutedEventArgs e) Private static void OnIsMonitoringChanged(DependencyObject d, DependencyPropert圜hangedEventArgs e) Public static readonly DependencyProperty PasswordLengthProperty =ĭependencyProperty.RegisterAttached("PasswordLength", typeof(int), typeof(PasswordBoxMonitor), new UIPropertyMetadata(0)) Obj.SetValue(PasswordLengthProperty, value) Public static void SetPasswordLength(DependencyObject obj, int value) Return (int)obj.GetValue(PasswordLengthProperty) Public static int GetPasswordLength(DependencyObject obj) Public static readonly DependencyProperty IsMonitoringProperty =ĭependencyProperty.RegisterAttached("IsMonitoring", typeof(bool), typeof(PasswordBoxMonitor), new UIPropertyMetadata(false, OnIsMonitoringChanged)) Obj.SetValue(IsMonitoringProperty, value) Public static void SetIsMonitoring(DependencyObject obj, bool value) Return (bool)obj.GetValue(IsMonitoringProperty) Public static bool GetIsMonitoring(DependencyObject obj)

wpf passwordbox watermark

Public class PasswordBoxMonitor : DependencyObject But you can use attached properties here. Also PasswordBox is sealed, so you can't override this notification behaviour.

wpf passwordbox watermark

The only problem here is that PasswordBox.Password property is not a dependency property, and you can't use it in trigger.

Wpf passwordbox watermark password#

General approach is the same: you write custom control style, and show watermark whenever password box is empty.






Wpf passwordbox watermark