Skip to content

Commit 96008e7

Browse files
committed
New UsernameCharacterCasing property for LoginDialogSettings
Closes #2683 [Question] Force TextBox uppercase in ShowLoginAsync
1 parent 4120c71 commit 96008e7

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

docs/release-notes/1.5.0.md

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
- Fix background and foreground usage of controls in a `Flyout` if user changes theme on the fly. [#2337](https://github.com/MahApps/MahApps.Metro/issues/2337) The `Flyout` has a different background, so we should override some background and foreground brushes and colors.
5151
- Use `GrayBrush7` and `WhiteBrush` for menu `Separator` instead fixed colors.
5252
- Fix BindingExpression at `DropDownButton`. Don't set `ItemTemplate`to `ContentTemplate`, `ItemTemplateSelector` to `ContentTemplateSelector` and `ItemStringFormat` to `ContentStringFormat`. This breaks the whole usage of the content stuff and shows a BindingExpression path error. [#2883](https://github.com/MahApps/MahApps.Metro/issues/2883)
53+
- New `UsernameCharacterCasing` property for `LoginDialogSettings` [#2683](https://github.com/MahApps/MahApps.Metro/issues/2683)
5354
5455
## Closed Issues
5556
@@ -70,3 +71,4 @@
7071
- [#2841](https://github.com/MahApps/MahApps.Metro/issues/2841) Modal flyout issue
7172
- [#2337](https://github.com/MahApps/MahApps.Metro/issues/2337) Flyout style from Accent to Light is not working
7273
- [#2883](https://github.com/MahApps/MahApps.Metro/issues/2883) Can Reproduce BindingExpression path error: ... property not found ... On DropDownButton
74+
- [#2683](https://github.com/MahApps/MahApps.Metro/issues/2683) [Question] Force TextBox uppercase in ShowLoginAsync

src/MahApps.Metro/MahApps.Metro.Shared/Controls/Dialogs/LoginDialog.cs

+16-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Security;
33
using System.Threading.Tasks;
44
using System.Windows;
5+
using System.Windows.Controls;
56
using System.Windows.Input;
67

78
namespace MahApps.Metro.Controls.Dialogs
@@ -10,21 +11,18 @@ public class LoginDialogSettings : MetroDialogSettings
1011
{
1112
private const string DefaultUsernameWatermark = "Username...";
1213
private const string DefaultPasswordWatermark = "Password...";
13-
private const Visibility DefaultNegativeButtonVisibility = Visibility.Collapsed;
14-
private const bool DefaultShouldHideUsername = false;
15-
private const bool DefaultEnablePasswordPreview = false;
16-
private const Visibility DefaultRememberCheckBoxVisibility = Visibility.Collapsed;
1714
private const string DefaultRememberCheckBoxText = "Remember";
1815

1916
public LoginDialogSettings()
2017
{
2118
this.UsernameWatermark = DefaultUsernameWatermark;
19+
this.UsernameCharacterCasing = CharacterCasing.Normal;
2220
this.PasswordWatermark = DefaultPasswordWatermark;
23-
this.NegativeButtonVisibility = DefaultNegativeButtonVisibility;
24-
this.ShouldHideUsername = DefaultShouldHideUsername;
21+
this.NegativeButtonVisibility = Visibility.Collapsed;
22+
this.ShouldHideUsername = false;
2523
this.AffirmativeButtonText = "Login";
26-
this.EnablePasswordPreview = DefaultEnablePasswordPreview;
27-
this.RememberCheckBoxVisibility = DefaultRememberCheckBoxVisibility;
24+
this.EnablePasswordPreview = false;
25+
this.RememberCheckBoxVisibility = Visibility.Collapsed;
2826
this.RememberCheckBoxText = DefaultRememberCheckBoxText;
2927
}
3028

@@ -34,6 +32,8 @@ public LoginDialogSettings()
3432

3533
public string UsernameWatermark { get; set; }
3634

35+
public CharacterCasing UsernameCharacterCasing { get; set; }
36+
3737
public bool ShouldHideUsername { get; set; }
3838

3939
public string PasswordWatermark { get; set; }
@@ -91,6 +91,7 @@ internal LoginDialog(MetroWindow parentWindow, LoginDialogSettings settings)
9191
this.InitializeComponent();
9292
this.Username = settings.InitialUsername;
9393
this.Password = settings.InitialPassword;
94+
this.UsernameCharacterCasing = settings.UsernameCharacterCasing;
9495
this.UsernameWatermark = settings.UsernameWatermark;
9596
this.PasswordWatermark = settings.PasswordWatermark;
9697
this.NegativeButtonButtonVisibility = settings.NegativeButtonVisibility;
@@ -247,6 +248,7 @@ protected override void OnLoaded()
247248
public static readonly DependencyProperty MessageProperty = DependencyProperty.Register("Message", typeof(string), typeof(LoginDialog), new PropertyMetadata(default(string)));
248249
public static readonly DependencyProperty UsernameProperty = DependencyProperty.Register("Username", typeof(string), typeof(LoginDialog), new PropertyMetadata(default(string)));
249250
public static readonly DependencyProperty UsernameWatermarkProperty = DependencyProperty.Register("UsernameWatermark", typeof(string), typeof(LoginDialog), new PropertyMetadata(default(string)));
251+
public static readonly DependencyProperty UsernameCharacterCasingProperty = DependencyProperty.Register("UsernameCharacterCasing", typeof(CharacterCasing), typeof(LoginDialog), new PropertyMetadata(default(CharacterCasing)));
250252
public static readonly DependencyProperty PasswordProperty = DependencyProperty.Register("Password", typeof(string), typeof(LoginDialog), new PropertyMetadata(default(string)));
251253
public static readonly DependencyProperty PasswordWatermarkProperty = DependencyProperty.Register("PasswordWatermark", typeof(string), typeof(LoginDialog), new PropertyMetadata(default(string)));
252254
public static readonly DependencyProperty AffirmativeButtonTextProperty = DependencyProperty.Register("AffirmativeButtonText", typeof(string), typeof(LoginDialog), new PropertyMetadata("OK"));
@@ -281,6 +283,12 @@ public string UsernameWatermark
281283
set { this.SetValue(UsernameWatermarkProperty, value); }
282284
}
283285

286+
public CharacterCasing UsernameCharacterCasing
287+
{
288+
get { return (CharacterCasing)this.GetValue(UsernameCharacterCasingProperty); }
289+
set { this.SetValue(UsernameCharacterCasingProperty, value); }
290+
}
291+
284292
public string PasswordWatermark
285293
{
286294
get { return (string)this.GetValue(PasswordWatermarkProperty); }

src/MahApps.Metro/MahApps.Metro/Themes/Dialogs/LoginDialog.xaml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<TextBox x:Name="PART_TextBox"
2222
Grid.Row="1"
2323
Margin="0 5 0 0"
24+
CharacterCasing="{Binding UsernameCharacterCasing, RelativeSource={RelativeSource AncestorType=Dialogs:LoginDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}"
2425
Controls:TextBoxHelper.SelectAllOnFocus="True"
2526
Controls:TextBoxHelper.Watermark="{Binding UsernameWatermark, RelativeSource={RelativeSource AncestorType=Dialogs:LoginDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}"
2627
Controls:VisibilityHelper.IsCollapsed="{Binding ShouldHideUsername, RelativeSource={RelativeSource AncestorType=Dialogs:LoginDialog, Mode=FindAncestor}, UpdateSourceTrigger=PropertyChanged}"

0 commit comments

Comments
 (0)