C# 注销后验证密码箱WPF

C# 注销后验证密码箱WPF,c#,wpf,validation,passwords,C#,Wpf,Validation,Passwords,我在我的WPF应用程序中验证了密码。我正在使用IDataErrorInfo接口。验证模板中有xml代码: <UserControl.Resources> <ControlTemplate x:Key="validationTemplate"> <DockPanel> <Border BorderBrush="Red" BorderThickness="1" Margin="0,-30,20,0" Heigh

我在我的WPF应用程序中验证了密码。我正在使用IDataErrorInfo接口。验证模板中有xml代码:

<UserControl.Resources>
    <ControlTemplate x:Key="validationTemplate">
        <DockPanel>
            <Border BorderBrush="Red" BorderThickness="1" Margin="0,-30,20,0" Height="23" Width="250" DockPanel.Dock="Bottom" >
            </Border>
            <TextBlock DockPanel.Dock="Right" Foreground="Red" FontSize="25" FontWeight="Bold" 
                        ToolTip="{Binding ElementName=Adorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">!</TextBlock>
            <AdornedElementPlaceholder Name="Adorner" VerticalAlignment="Center" >
            </AdornedElementPlaceholder>
        </DockPanel>
    </ControlTemplate>

    <DataTemplate x:Key="ErrorViewerItemTemplate" DataType="string" >
        <StackPanel Orientation="Horizontal">
            <Ellipse Fill="Red" Width="5" Height="5" VerticalAlignment="Center" 
                     HorizontalAlignment="Center" Margin="5,0,0,0" />
            <TextBlock Text="{Binding}" FontSize="11" FontStyle="Italic" Foreground="red" Padding="2" Margin="5,0,0,0" />
        </StackPanel>
    </DataTemplate>
</UserControl.Resources>

<Grid x:Name="mainGrid">
        <Label x:Name="passLabel" Content="Password" FontWeight="Bold" />
        <Border BorderBrush="Green" BorderThickness="1" HorizontalAlignment="Left" Margin="135,40,0,0" Height="23">
            <PasswordBox local:PasswordBoxAssistant.BindPassword="True" 
            x:Name="passwordBox" Validation.ErrorTemplate="{StaticResource validationTemplate}" HorizontalAlignment="Left" Height="23" Margin="0,0,0,0">
                <local:PasswordBoxAssistant.BoundPassword>
                    <Binding Path="Password" UpdateSourceTrigger="PropertyChanged" ValidatesOnDataErrors="True" >
                        <Binding.ValidationRules>
                            <NotifyDataErrorValidationRule />
                        </Binding.ValidationRules>
                    </Binding>
                </local:PasswordBoxAssistant.BoundPassword>
            </PasswordBox>
        </Border>
</Grid>
用于绑定我使用的密码

登录验证工作正常(在用户首次登录时),

但当用户注销时,登录窗口上的验证不起作用。

我已尝试设置绑定的
Mode=“TwoWay”
,并且
validatesOnDaerRors=True,
ValidatesOnExceptions=True
,但它没有解决我的问题


因此,请至少以某种方式帮助我修复它。)

您确定“ConnectionSettings”在注销时被丢弃,并且是为登录新创建的吗?换句话说:你确定你的视图模型中没有有效的密码吗?@SvenBardos,是的,我已经检查过了。@SvenBardos和我有登录名和另外两个字段,我也在用这种方式检查它们。注销后,我对它们没有问题,但它们是文本框。
class ConnectionSettings : INotifyPropertyChanged, IDataErrorInfo
{
    private string _password;

    public string Password
    {
        get
        {
            return _password;
        }
        set
        {
            _password = value;
            OnPropertyChanged(nameof(Password));
        }
    }

... // realization INotifyPropertyChanged interface

    public string this[string columnName]
    {
        get
        {
            string errorMessage = String.Empty;
            switch (columnName)
            {
                ...
                case "Password":
                    if (string.IsNullOrEmpty(Password))
                    {
                        errorMessage = "Validation error: Enter the data in the field";
                    }
                    else if (!RegexPasswordValid(Password))
                    {
                        errorMessage = "Validation error: The password does not match the template or short password (minimum 8 characters)";
                    }
                    break;
                 ...
            }
            return errorMessage;
        }
    }

    private bool RegexPasswordValid(string value)
    {
        string pattern = @"^(\w{8,})$";
        Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
        bool isRegexValid = (regex.IsMatch(value)) ? true : false;
        return isRegexValid;
    }

    public string Error
    {
        get { throw new NotImplementedException(); }
    }