2 Коміти e6c557276a ... 76df301377

Автор SHA1 Опис Дата
  宝臣 王 76df301377 Merge branch 'master' of https://git.xxb.lttc.cn/wangbc/UniformMaterialManagementSystem 3 місяців тому
  宝臣 王 d9856193ff 优化注册页面,添加必填项提示信息 3 місяців тому

+ 6 - 6
UniformMaterialManagementSystem/Resources/ControlStyle.xaml

@@ -6,12 +6,7 @@
 
     <ControlTemplate x:Key="ValidationErrorTemplate">
         <StackPanel>
-            <Border
-                BorderBrush="Red"
-                BorderThickness="1"
-                CornerRadius="5">
-                <AdornedElementPlaceholder x:Name="AdornedElement" />
-            </Border>
+            <AdornedElementPlaceholder />
 
             <TextBlock
                 HorizontalAlignment="Right"
@@ -529,6 +524,11 @@
                         <Trigger SourceName="Popup" Property="AllowsTransparency" Value="true">
                             <Setter TargetName="DropDownBorder" Property="Margin" Value="0,4,0,0" />
                         </Trigger>
+
+                        <Trigger Property="Validation.HasError" Value="True">
+                            <!--<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />-->
+                            <Setter TargetName="myBorder" Property="BorderBrush" Value="Red" />
+                        </Trigger>
                     </ControlTemplate.Triggers>
                 </ControlTemplate>
             </Setter.Value>

+ 3 - 0
UniformMaterialManagementSystem/ViewModels/RegisterPageViewModel.cs

@@ -27,18 +27,21 @@ namespace UniformMaterialManagementSystem.ViewModels
         };
 
         [ObservableProperty]
+        [Required(ErrorMessage = "单位类型不能为空")]
         private string _selectedUnitType = string.Empty;
 
         [ObservableProperty]
         private ICollection<SupervisionUnit> _units = [];
 
         [ObservableProperty]
+        [Required(ErrorMessage = "单位不能为空")]
         private SupervisionUnit _selectedUnit = null!;
 
         [ObservableProperty]
         private ICollection<Company> _companyList = [];
 
         [ObservableProperty]
+        [Required(ErrorMessage = "公司不能为空")]
         private Company? _selectedCompany;
 
         [ObservableProperty]

+ 34 - 4
UniformMaterialManagementSystem/Views/LoginAndRegister/RegisterPage.xaml

@@ -14,6 +14,26 @@
     <UserControl.Resources>
         <Style TargetType="TextBox">
             <Setter Property="Validation.ErrorTemplate" Value="{StaticResource ValidationErrorTemplate}" />
+            <Setter Property="Template">
+                <Setter.Value>
+                    <ControlTemplate TargetType="TextBox">
+                        <Border
+                            x:Name="border"
+                            Background="White"
+                            BorderBrush="#019b9b"
+                            BorderThickness="1"
+                            CornerRadius="5">
+                            <ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
+                        </Border>
+
+                        <ControlTemplate.Triggers>
+                            <Trigger Property="Validation.HasError" Value="True">
+                                <Setter TargetName="border" Property="BorderBrush" Value="Red" />
+                            </Trigger>
+                        </ControlTemplate.Triggers>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
         </Style>
         <Style TargetType="PasswordBox">
             <Setter Property="Validation.ErrorTemplate" Value="{StaticResource ValidationErrorTemplate}" />
@@ -21,12 +41,19 @@
                 <Setter.Value>
                     <ControlTemplate TargetType="PasswordBox">
                         <Border
+                            x:Name="border"
                             Background="White"
                             BorderBrush="#019b9b"
                             BorderThickness="1"
                             CornerRadius="5">
                             <ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                         </Border>
+
+                        <ControlTemplate.Triggers>
+                            <Trigger Property="Validation.HasError" Value="True">
+                                <Setter TargetName="border" Property="BorderBrush" Value="Red" />
+                            </Trigger>
+                        </ControlTemplate.Triggers>
                     </ControlTemplate>
                 </Setter.Value>
             </Setter>
@@ -113,9 +140,10 @@
                         Padding="5,0,0,0"
                         BorderBrush="#019b9b"
                         ItemsSource="{Binding UnitTypes}"
-                        SelectedValue="{Binding SelectedUnitType}"
+                        SelectedValue="{Binding SelectedUnitType, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"
                         SelectedValuePath="Key"
-                        Style="{StaticResource WpfComboBoxStyle}">
+                        Style="{StaticResource WpfComboBoxStyle}"
+                        Validation.ErrorTemplate="{StaticResource ValidationErrorTemplate}">
                         <ComboBox.ItemTemplate>
                             <DataTemplate DataType="{x:Type sys:KeyValuePair`2}">
                                 <Label
@@ -144,7 +172,8 @@
                         DisplayMemberPath="Name"
                         ItemsSource="{Binding Units}"
                         SelectedItem="{Binding SelectedUnit}"
-                        Style="{StaticResource WpfComboBoxStyle}" />
+                        Style="{StaticResource WpfComboBoxStyle}"
+                        Validation.ErrorTemplate="{StaticResource ValidationErrorTemplate}" />
 
                     <Label
                         Grid.Row="4"
@@ -163,7 +192,8 @@
                         DisplayMemberPath="Name"
                         ItemsSource="{Binding CompanyList}"
                         SelectedItem="{Binding SelectedCompany}"
-                        Style="{StaticResource WpfComboBoxStyle}" />
+                        Style="{StaticResource WpfComboBoxStyle}"
+                        Validation.ErrorTemplate="{StaticResource ValidationErrorTemplate}" />
 
                     <Label
                         Grid.Row="6"