From 3fcd2f96e4ebbd50359ae9ebeb31addef66b83c1 Mon Sep 17 00:00:00 2001 From: Stricted Date: Thu, 29 Oct 2015 09:34:44 +0100 Subject: [PATCH] more --- .../PasswordHelper.cs | 83 +++++++++++++++++++ ...edportHybridControl.Implementations.csproj | 3 + SpeedportHybridControl/App.xaml | 3 +- SpeedportHybridControl/MainWindow.xaml | 2 +- .../Model/LoginPageModel.cs | 72 ++++++++++++++++ .../SpeedportHybridControl.csproj | 1 + .../model/MainWindowModel.cs | 7 ++ SpeedportHybridControl/page/LoginPage.xaml | 15 ++-- SpeedportHybridControl/page/LoginPage.xaml.cs | 2 + 9 files changed, 179 insertions(+), 9 deletions(-) create mode 100644 SpeedportHybridControl.Implementations/PasswordHelper.cs create mode 100644 SpeedportHybridControl/Model/LoginPageModel.cs 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 @@ -