complete login function and login window also add attached properties and helper classes for securestring

This commit is contained in:
Rene Schwarz
2021-04-03 23:52:00 +02:00
parent 077f622115
commit a42f756d78
32 changed files with 377 additions and 37 deletions

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
namespace Server_Dashboard {
public abstract class BaseAttachedProperty<Parent, Property>
where Parent : BaseAttachedProperty<Parent, Property>, new() {
public event Action<DependencyObject, DependencyPropertyChangedEventArgs> ValueChanged = (sender, e) => { };
public static Parent Instance { get; private set; } = new Parent();
public static readonly DependencyProperty ValueProperty = DependencyProperty.RegisterAttached("Value", typeof(Property), typeof(BaseAttachedProperty<Parent, Property>), new PropertyMetadata(new PropertyChangedCallback(OnValuePropertyChanged)));
private static void OnValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
Instance.OnValueChanged(d, e);
Instance.ValueChanged(d, e);
}
public static Property GetValue(DependencyObject d) => (Property)d.GetValue(ValueProperty);
public static void SetValue(DependencyObject d, Property value) => d.SetValue(ValueProperty, value);
public virtual void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { }
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
namespace Server_Dashboard {
public class MonitorPasswordProperty : BaseAttachedProperty<MonitorPasswordProperty, bool> {
public override void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) {
var passwordBox = sender as PasswordBox;
if (passwordBox == null)
return;
passwordBox.PasswordChanged -= PasswordBox_PasswordChanged;
if ((bool)e.NewValue) {
HasTextProperty.SetValue(passwordBox);
passwordBox.PasswordChanged += PasswordBox_PasswordChanged;
}
}
private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e) {
HasTextProperty.SetValue((PasswordBox)sender);
}
}
public class HasTextProperty : BaseAttachedProperty<HasTextProperty, bool> {
public static void SetValue(DependencyObject sender) {
SetValue(sender, ((PasswordBox)sender).SecurePassword.Length < 1);
}
}
}