schangxiang@126.com
2025-11-04 f5ed29dc26c7cd952d56ec5721a2efc43cd25992
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:HxUserManagement"
    xmlns:ctrl="clr-namespace:HxUserManagement.Controls">
    
 
    <Style x:Key="passwordToggleButtonStyle" TargetType="ToggleButton">
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Cursor" Value="Hand"/>
        <Setter Property="Width" Value="24"/>
        <Setter Property="Height" Value="24"/>
        <Setter Property="Background" Value="White"/>
        <Setter Property="Foreground" Value="Black"/>
        <Setter Property="IsChecked" Value="False"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Grid Background="{TemplateBinding Background}">
                        <Image x:Name="img_EyeOn" Source="pack://application:,,,/HxUserManagement;component/Assets/eyeon.png" Width="24" Height="24" Visibility="Hidden"/>
                        <Image x:Name="img_EyeOff" Source="pack://application:,,,/HxUserManagement;component/Assets/eyeoff.png" Width="24" Height="24" Visibility="Visible"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="True">
                            <Setter TargetName="img_EyeOn" Property="Visibility" Value="Visible"/>
                            <Setter TargetName="img_EyeOff" Property="Visibility" Value="Hidden"/>
                        </Trigger>
                        <Trigger Property="IsChecked" Value="False">
                            <Setter TargetName="img_EyeOn" Property="Visibility" Value="Hidden"/>
                            <Setter TargetName="img_EyeOff" Property="Visibility" Value="Visible"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
 
    <Style x:Key="textBoxStyle" TargetType="TextBox">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate >
                    <Grid>
                        <Border x:Name="BackBorder" SnapsToDevicePixels="true" Background="{TemplateBinding Background}"
                            BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}">
                            <ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsFocused" Value="True" >
                            <Setter Property="Background" TargetName="BackBorder" Value="White"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="TextBox.Foreground" Value="Gray"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <Style TargetType="{x:Type ctrl:HxPasswordBox}">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Foreground" Value="Black"/>
        <Setter Property="Margin" Value="5"/>
        <Setter Property="FontSize" Value="16"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="BorderBrush" Value="DarkGray"/>
        <Setter Property="Padding" Value="5,2"/>
        <Setter Property="PasswrodChar" Value="*"/>
        <!--<Setter Property="ShowWaterMark" Value="True"/>
        <Setter Property="WaterMark" Value="Pin"/>-->
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="AllowDrop" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ctrl:HxPasswordBox}">
                    <Border Grid.Column="1" Background="Transparent" BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"
                               >
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <TextBox x:Name="PART_PasswordText" BorderBrush="Transparent" BorderThickness="0" HorizontalAlignment="Stretch" 
                                         Foreground="{TemplateBinding Foreground}" Background="Transparent" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                         HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Visibility="Hidden"
                                         Text="{TemplateBinding Password}" Style="{DynamicResource textBoxStyle}"/>
                            <PasswordBox x:Name="PART_Password" BorderBrush="Transparent" BorderThickness="0" HorizontalAlignment="Stretch"
                                             Foreground="{TemplateBinding Foreground}" Background="Transparent" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                             HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"/>
    
                            <!--<TextBlock x:Name="watermark" Text="{TemplateBinding WaterMark}" Background="Transparent" IsHitTestVisible="False" 
                                           Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
                                           HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                           Foreground="{DynamicResource BrushWaterMark}" Visibility="Collapsed"/>-->
    
                            <ToggleButton x:Name="toggle" Grid.Column="1" Style="{StaticResource passwordToggleButtonStyle}"
                                              IsChecked="{Binding ShowPassword, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, RelativeSource ={RelativeSource TemplatedParent}}"/>
                        </Grid>
                    </Border>
 
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsFocused" Value="True">
                            <Setter Property="BorderBrush" Value="{DynamicResource BrushPrimary}"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="BorderBrush" Value="{DynamicResource BrushPrimary}"/>
                        </Trigger>
 
                        <DataTrigger Binding="{Binding ElementName=toggle,Path=IsChecked}" Value="True">
                            <Setter TargetName="PART_PasswordText" Property="Visibility" Value="Visible"/>
                            <Setter TargetName="PART_Password" Property="Visibility" Value="Hidden"/>
                        </DataTrigger>
                        <DataTrigger Binding="{Binding ElementName=toggle,Path=IsChecked}" Value="False">
                            <Setter TargetName="PART_PasswordText" Property="Visibility" Value="Hidden"/>
                            <Setter TargetName="PART_Password" Property="Visibility" Value="Visible"/>
                        </DataTrigger>
 
                        <!--<MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsEnabled" Value="True"/>
                                <Condition Property="HasText" Value="False"/>
                                <Condition Property="ShowWaterMark" Value="true"/>
                            </MultiTrigger.Conditions>
                            <MultiTrigger.Setters>
                                <Setter TargetName="watermark" Property="Visibility" Value="Visible"/>
                            </MultiTrigger.Setters>
                        </MultiTrigger>-->
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>