-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1873 from bitbeans/master
New try for LoginDialog Password Preview Feature
- Loading branch information
Showing
9 changed files
with
656 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// -------------------------------------------------------------------- | ||
// Obtained from: WPFSmartLibrary | ||
// For more information see : http://wpfsmartlibrary.codeplex.com/ | ||
// (by DotNetMastermind) | ||
// -------------------------------------------------------------------- | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Interactivity; | ||
|
||
namespace MahApps.Metro.Behaviours | ||
{ | ||
public class PasswordBoxBindingBehavior : Behavior<PasswordBox> | ||
{ | ||
#region Fields | ||
|
||
private static bool IsUpdating; | ||
|
||
#endregion | ||
|
||
#region DependencyProperty - Password ("string") | ||
|
||
public static string GetPassword(DependencyObject dpo) | ||
{ | ||
return (string)dpo.GetValue(PasswordProperty); | ||
} | ||
public static void SetPassword(DependencyObject dpo, string value) | ||
{ | ||
dpo.SetValue(PasswordProperty, value); | ||
} | ||
/// <summary> | ||
/// Gets or sets the bindable Password property on the PasswordBox control. This is a dependency property. | ||
/// </summary> | ||
public static readonly DependencyProperty PasswordProperty = | ||
DependencyProperty.RegisterAttached("Password", typeof(string), | ||
typeof(PasswordBoxBindingBehavior), | ||
new FrameworkPropertyMetadata(String.Empty, | ||
new PropertyChangedCallback(OnPasswordPropertyChanged))); | ||
/// <summary> | ||
/// Handles changes to the 'Password' attached property. | ||
/// </summary> | ||
private static void OnPasswordPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) | ||
{ | ||
PasswordBox targetPasswordBox = sender as PasswordBox; | ||
if (targetPasswordBox != null) | ||
{ | ||
targetPasswordBox.PasswordChanged -= PasswordBox_PasswordChanged; | ||
if (IsUpdating == false) | ||
{ | ||
targetPasswordBox.Password = (string)e.NewValue; | ||
} | ||
targetPasswordBox.PasswordChanged += PasswordBox_PasswordChanged; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Handle the 'PasswordChanged'-event on the PasswordBox | ||
/// </summary> | ||
private static void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e) | ||
{ | ||
PasswordBox passwordBox = sender as PasswordBox; | ||
IsUpdating = true; | ||
SetPassword(passwordBox, passwordBox.Password); | ||
IsUpdating = false; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// -------------------------------------------------------------------- | ||
// Obtained from: WPFSmartLibrary | ||
// For more information see : http://wpfsmartlibrary.codeplex.com/ | ||
// (by DotNetMastermind) | ||
// -------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Globalization; | ||
using System.Windows; | ||
using System.Windows.Data; | ||
using System.Windows.Markup; | ||
|
||
namespace MahApps.Metro.Converters | ||
{ | ||
/// <summary> | ||
/// Converts a String into a Visibility enumeration (and back) | ||
/// The FalseEquivalent can be declared with the "FalseEquivalent" property | ||
/// </summary> | ||
[ValueConversion(typeof (string), typeof (Visibility))] | ||
[MarkupExtensionReturnType(typeof (StringToVisibilityConverter))] | ||
public class StringToVisibilityConverter : MarkupExtension, IValueConverter | ||
{ | ||
/// <summary> | ||
/// Initialize the properties with standard values | ||
/// </summary> | ||
public StringToVisibilityConverter() | ||
{ | ||
FalseEquivalent = Visibility.Collapsed; | ||
OppositeStringValue = false; | ||
} | ||
|
||
/// <summary> | ||
/// FalseEquivalent (default : Visibility.Collapsed => see Constructor) | ||
/// </summary> | ||
public Visibility FalseEquivalent { get; set; } | ||
|
||
/// <summary> | ||
/// Define whether the opposite boolean value is crucial (default : false) | ||
/// </summary> | ||
public bool OppositeStringValue { get; set; } | ||
|
||
#region MarkupExtension "overrides" | ||
|
||
public override object ProvideValue(IServiceProvider serviceProvider) | ||
{ | ||
return new StringToVisibilityConverter | ||
{ | ||
FalseEquivalent = FalseEquivalent, | ||
OppositeStringValue = OppositeStringValue | ||
}; | ||
} | ||
|
||
#endregion | ||
|
||
#region IValueConverter Members | ||
|
||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
if (value is string && targetType == typeof (Visibility)) | ||
{ | ||
if (OppositeStringValue) | ||
{ | ||
return (((string) value).ToLower().Equals(String.Empty)) ? Visibility.Visible : FalseEquivalent; | ||
} | ||
return (((string) value).ToLower().Equals(String.Empty)) ? FalseEquivalent : Visibility.Visible; | ||
} | ||
return value; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
if (value is Visibility) | ||
{ | ||
if (OppositeStringValue) | ||
{ | ||
return ((Visibility) value == Visibility.Visible) ? String.Empty : "visible"; | ||
} | ||
return ((Visibility) value == Visibility.Visible) ? "visible" : String.Empty; | ||
} | ||
return value; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.