From: Stricted Date: Thu, 29 Oct 2015 08:34:44 +0000 (+0100) Subject: more X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=3fcd2f96e4ebbd50359ae9ebeb31addef66b83c1;p=GitHub%2FStricted%2FSpeedportHybridControl.git more --- diff --git a/SpeedportHybridControl.Implementations/PasswordHelper.cs b/SpeedportHybridControl.Implementations/PasswordHelper.cs new file mode 100644 index 0000000..8782491 --- /dev/null +++ b/SpeedportHybridControl.Implementations/PasswordHelper.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; + +namespace SpeedportHybridControl.Implementations { + public static class PasswordHelper { + public static readonly DependencyProperty PasswordProperty = + DependencyProperty.RegisterAttached("Password", + typeof(string), typeof(PasswordHelper), + new FrameworkPropertyMetadata(string.Empty, OnPasswordPropertyChanged)); + + public static readonly DependencyProperty AttachProperty = + DependencyProperty.RegisterAttached("Attach", + typeof(bool), typeof(PasswordHelper), new PropertyMetadata(false, Attach)); + + private static readonly DependencyProperty IsUpdatingProperty = + DependencyProperty.RegisterAttached("IsUpdating", typeof(bool), + typeof(PasswordHelper)); + + + public static void SetAttach (DependencyObject dp, bool value) { + dp.SetValue(AttachProperty, value); + } + + public static bool GetAttach (DependencyObject dp) { + return (bool)dp.GetValue(AttachProperty); + } + + public static string GetPassword (DependencyObject dp) { + return (string)dp.GetValue(PasswordProperty); + } + + public static void SetPassword (DependencyObject dp, string value) { + dp.SetValue(PasswordProperty, value); + } + + private static bool GetIsUpdating (DependencyObject dp) { + return (bool)dp.GetValue(IsUpdatingProperty); + } + + private static void SetIsUpdating (DependencyObject dp, bool value) { + dp.SetValue(IsUpdatingProperty, value); + } + + private static void OnPasswordPropertyChanged (DependencyObject sender, + DependencyPropertyChangedEventArgs e) { + PasswordBox passwordBox = sender as PasswordBox; + passwordBox.PasswordChanged -= PasswordChanged; + + if (!(bool)GetIsUpdating(passwordBox)) { + passwordBox.Password = (string)e.NewValue; + } + passwordBox.PasswordChanged += PasswordChanged; + } + + private static void Attach (DependencyObject sender, + DependencyPropertyChangedEventArgs e) { + PasswordBox passwordBox = sender as PasswordBox; + + if (passwordBox == null) + return; + + if ((bool)e.OldValue) { + passwordBox.PasswordChanged -= PasswordChanged; + } + + if ((bool)e.NewValue) { + passwordBox.PasswordChanged += PasswordChanged; + } + } + + private static void PasswordChanged (object sender, RoutedEventArgs e) { + PasswordBox passwordBox = sender as PasswordBox; + SetIsUpdating(passwordBox, true); + SetPassword(passwordBox, passwordBox.Password); + SetIsUpdating(passwordBox, false); + } + } +} diff --git a/SpeedportHybridControl.Implementations/SpeedportHybridControl.Implementations.csproj b/SpeedportHybridControl.Implementations/SpeedportHybridControl.Implementations.csproj index e2cfa21..ecba430 100644 --- a/SpeedportHybridControl.Implementations/SpeedportHybridControl.Implementations.csproj +++ b/SpeedportHybridControl.Implementations/SpeedportHybridControl.Implementations.csproj @@ -39,6 +39,7 @@ True + @@ -47,11 +48,13 @@ + + diff --git a/SpeedportHybridControl/App.xaml b/SpeedportHybridControl/App.xaml index 6a27a04..40e8a08 100644 --- a/SpeedportHybridControl/App.xaml +++ b/SpeedportHybridControl/App.xaml @@ -7,7 +7,8 @@ - + + diff --git a/SpeedportHybridControl/MainWindow.xaml b/SpeedportHybridControl/MainWindow.xaml index 2fe46ad..15b3040 100644 --- a/SpeedportHybridControl/MainWindow.xaml +++ b/SpeedportHybridControl/MainWindow.xaml @@ -21,7 +21,7 @@ -