Browse Source

输入密码框增加大小写切换显示

KWD 2 months ago
parent
commit
c1a6cc19bc
2 changed files with 62 additions and 36 deletions
  1. 42 35
      TeamAAS-VM/Views/User/LoginView.xaml
  2. 20 1
      TeamAAS-VM/Views/User/LoginView.xaml.cs

+ 42 - 35
TeamAAS-VM/Views/User/LoginView.xaml

@@ -36,41 +36,48 @@
                         <RowDefinition Height="20*" />
                         <RowDefinition Height="20*" />
                     </Grid.RowDefinitions>
-                    <TextBlock
-                        HorizontalAlignment="Center"
-                        FontSize="32"
-                        Text="{lex:Loc 登录}" />
-                    <materialDesign:PackIcon
-                        Grid.Row="1"
-                        VerticalAlignment="Center"
-                        Kind="User" />
-                    <ComboBox
-                        Grid.Row="1"
-                        Height="50"
-                        Margin="20"
-                        HorizontalContentAlignment="Left"
-                        materialDesign:HintAssist.Hint="{lex:Loc 用户}"
-                        ItemsSource="{Binding UserNameList, Mode=TwoWay}"
-                        SelectedItem="{Binding SelectedUserName}"
-                        Style="{StaticResource MaterialDesignFloatingHintComboBox}" />
-                    <materialDesign:PackIcon
-                        Grid.Row="2"
-                        VerticalAlignment="Center"
-                        Kind="Password" />
-                    <PasswordBox
-                        Grid.Row="2"
-                        Height="50"
-                        Margin="20,0,20,0"
-                        HorizontalContentAlignment="Left"
-                        materialDesign:HintAssist.HelperText="{lex:Loc 请输入用户登录密码}"
-                        materialDesign:HintAssist.Hint="{lex:Loc 密码}"
-                        materialDesign:PasswordBoxAssist.Password="{Binding Path=UserPassword, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True}"
-                        materialDesign:TextFieldAssist.HasClearButton="True"
-                        Style="{StaticResource MaterialDesignFloatingHintPasswordBox}" />
-                    <Grid
-                        Grid.Row="3"
-                        Height="40"
-                        Margin="20,5,20,0">
+                    <TextBlock Text="{lex:Loc 登录}"
+                               FontSize="32"
+                               HorizontalAlignment="Center" />
+                    <materialDesign:PackIcon Grid.Row="1"
+                                             Kind="User"
+                                             VerticalAlignment="Center" />
+                    <ComboBox Grid.Row="1"
+                              Height="50"
+                              Margin="20"
+                              materialDesign:HintAssist.Hint="{lex:Loc 用户}"
+                              HorizontalContentAlignment="Left"
+                              Style="{StaticResource MaterialDesignFloatingHintComboBox}"
+                              ItemsSource="{Binding UserNameList,Mode=TwoWay}"
+                              SelectedItem="{Binding SelectedUserName}">
+                    </ComboBox>
+                    <materialDesign:PackIcon Grid.Row="2"
+                                             Kind="Password"
+                                             VerticalAlignment="Center"/>
+                    <PasswordBox x:Name="PwdBox"
+             Grid.Row="2"
+             Height="50"
+             Margin="20,0,20,0"
+             KeyUp="PwdBox_KeyUp"
+            GotFocus="PwdBox_GotFocus"
+             HorizontalContentAlignment="Left"
+             Style="{StaticResource MaterialDesignFloatingHintPasswordBox}"
+             materialDesign:HintAssist.HelperText="{lex:Loc 请输入用户登录密码}"
+             materialDesign:HintAssist.Hint="{lex:Loc 密码}"
+             materialDesign:TextFieldAssist.HasClearButton="True"
+             materialDesign:PasswordBoxAssist.Password="{Binding Path=UserPassword, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True}"/>
+                    <TextBlock x:Name="CapsLockText"
+           Grid.Row="2"
+           Margin="25,52,0,0"
+           HorizontalAlignment="Left"
+           VerticalAlignment="Top"
+           FontSize="12"
+           Foreground="OrangeRed"
+           Text="⚠ 大写锁定已开启"
+           Visibility="Collapsed"/>
+                    <Grid Grid.Row="3"
+                          Height="40"
+                          Margin="20,5,20,0">
                         <!--<CheckBox Content="{lex:Loc 记住用户}"
                                   Foreground="Black"
                                   Style="{StaticResource MaterialDesignCheckBox}"

+ 20 - 1
TeamAAS-VM/Views/User/LoginView.xaml.cs

@@ -1,4 +1,7 @@
-using System.Windows.Controls;
+using MaterialDesignThemes.Wpf;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Input;
 
 namespace TeamAAS_VP.Views.User
 {
@@ -11,5 +14,21 @@ namespace TeamAAS_VP.Views.User
         {
             InitializeComponent();
         }
+        private void PwdBox_GotFocus(object sender, RoutedEventArgs e)
+        {
+            PwdBox.SetValue(
+                HintAssist.HelperTextProperty,
+                Keyboard.IsKeyToggled(Key.CapsLock)
+                    ? "⚠ 大写锁定已开启"
+                    : "请输入用户登录密码");
+        }
+        private void PwdBox_KeyUp(object sender, KeyEventArgs e)
+        {
+            PwdBox.SetValue(
+                HintAssist.HelperTextProperty,
+                Keyboard.IsKeyToggled(Key.CapsLock)
+                    ? "⚠ 大写锁定已开启"
+                    : "请输入用户登录密码");
+        }
     }
 }