diff --git a/MahApps.Metro/Controls/Dialogs/LoginDialog.cs b/MahApps.Metro/Controls/Dialogs/LoginDialog.cs index 1bc5531d30..3fd8550d6e 100644 --- a/MahApps.Metro/Controls/Dialogs/LoginDialog.cs +++ b/MahApps.Metro/Controls/Dialogs/LoginDialog.cs @@ -10,6 +10,7 @@ public class LoginDialogSettings : MetroDialogSettings private const string DefaultUsernameWatermark = "Username..."; private const string DefaultPasswordWatermark = "Password..."; private const Visibility DefaultNegativeButtonVisibility = Visibility.Collapsed; + private const bool DefaultShouldHideUsername = false; private const bool DefaultEnablePasswordPreview = false; public LoginDialogSettings() @@ -17,6 +18,7 @@ public LoginDialogSettings() UsernameWatermark = DefaultUsernameWatermark; PasswordWatermark = DefaultPasswordWatermark; NegativeButtonVisibility = DefaultNegativeButtonVisibility; + ShouldHideUsername = DefaultShouldHideUsername; AffirmativeButtonText = "Login"; EnablePasswordPreview = DefaultEnablePasswordPreview; } @@ -27,6 +29,8 @@ public LoginDialogSettings() public string UsernameWatermark { get; set; } + public bool ShouldHideUsername { get; set; } + public string PasswordWatermark { get; set; } public Visibility NegativeButtonVisibility { get; set; } @@ -56,6 +60,7 @@ internal LoginDialog(MetroWindow parentWindow, LoginDialogSettings settings) UsernameWatermark = settings.UsernameWatermark; PasswordWatermark = settings.PasswordWatermark; NegativeButtonButtonVisibility = settings.NegativeButtonVisibility; + ShouldHideUsername = settings.ShouldHideUsername; } internal Task WaitForButtonPressAsync() @@ -63,7 +68,7 @@ internal Task WaitForButtonPressAsync() Dispatcher.BeginInvoke(new Action(() => { this.Focus(); - if (string.IsNullOrEmpty(PART_TextBox.Text)) + if (string.IsNullOrEmpty(PART_TextBox.Text) && !ShouldHideUsername) { PART_TextBox.Focus(); } @@ -200,6 +205,7 @@ protected override void OnLoaded() public static readonly DependencyProperty AffirmativeButtonTextProperty = DependencyProperty.Register("AffirmativeButtonText", typeof(string), typeof(LoginDialog), new PropertyMetadata("OK")); public static readonly DependencyProperty NegativeButtonTextProperty = DependencyProperty.Register("NegativeButtonText", typeof(string), typeof(LoginDialog), new PropertyMetadata("Cancel")); public static readonly DependencyProperty NegativeButtonButtonVisibilityProperty = DependencyProperty.Register("NegativeButtonButtonVisibility", typeof(Visibility), typeof(LoginDialog), new PropertyMetadata(Visibility.Collapsed)); + public static readonly DependencyProperty ShouldHideUsernameProperty = DependencyProperty.Register("ShouldHideUsername", typeof(bool), typeof(LoginDialog), new PropertyMetadata(false)); public string Message { @@ -248,5 +254,11 @@ public Visibility NegativeButtonButtonVisibility get { return (Visibility)GetValue(NegativeButtonButtonVisibilityProperty); } set { SetValue(NegativeButtonButtonVisibilityProperty, value); } } + + public bool ShouldHideUsername + { + get { return (bool)GetValue(ShouldHideUsernameProperty); } + set { SetValue(ShouldHideUsernameProperty, value); } + } } } diff --git a/MahApps.Metro/Converters/InvertedBooleanToVisibilityConverter.cs b/MahApps.Metro/Converters/InvertedBooleanToVisibilityConverter.cs new file mode 100644 index 0000000000..7d79808473 --- /dev/null +++ b/MahApps.Metro/Converters/InvertedBooleanToVisibilityConverter.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Data; + +namespace MahApps.Metro.Converters +{ + public class InvertedBooleanToVisibilityConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var shouldBeCollapsed = false; + + if(value is bool) + { + shouldBeCollapsed = (bool)value; + } + else if(value is bool?) + { + var valueAsNullable = (bool?)value; + shouldBeCollapsed = valueAsNullable.HasValue ? valueAsNullable.Value : false; + } + + return shouldBeCollapsed ? Visibility.Collapsed : Visibility.Hidden; + + + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is Visibility) + { + return (Visibility)value == Visibility.Collapsed; + } + else + { + return false; + } + } + } +} diff --git a/MahApps.Metro/MahApps.Metro.NET45.csproj b/MahApps.Metro/MahApps.Metro.NET45.csproj index cd3a328e33..bd58aff9f6 100644 --- a/MahApps.Metro/MahApps.Metro.NET45.csproj +++ b/MahApps.Metro/MahApps.Metro.NET45.csproj @@ -198,6 +198,7 @@ + diff --git a/MahApps.Metro/MahApps.Metro.csproj b/MahApps.Metro/MahApps.Metro.csproj index 9ee1adad54..ebb2a82b73 100644 --- a/MahApps.Metro/MahApps.Metro.csproj +++ b/MahApps.Metro/MahApps.Metro.csproj @@ -162,6 +162,7 @@ + diff --git a/MahApps.Metro/Themes/Dialogs/LoginDialog.xaml b/MahApps.Metro/Themes/Dialogs/LoginDialog.xaml index fbd883698e..3b37e9b9a2 100644 --- a/MahApps.Metro/Themes/Dialogs/LoginDialog.xaml +++ b/MahApps.Metro/Themes/Dialogs/LoginDialog.xaml @@ -1,9 +1,13 @@  + + + +