How to bind to a PasswordBox in MVVM

前端 未结 30 2102
执念已碎
执念已碎 2020-11-22 11:50

I have come across a problem with binding to a PasswordBox. It seems it\'s a security risk but I am using the MVVM pattern so I wish to bypass this. I found som

30条回答
  •  遥遥无期
    2020-11-22 12:21

    well my answerd is more simple just in the for the MVVM pattern

    in class viewmodel

    public string password;
    
    PasswordChangedCommand = new DelegateCommand(PasswordChanged);
    
    Private void PasswordChanged(RoutedEventArgs obj)
    
    {
    
        var e = (WatermarkPasswordBox)obj.OriginalSource;
    
        //or depending or what are you using
    
        var e = (PasswordBox)obj.OriginalSource;
    
        password =e.Password;
    
    }
    

    the password property of the PasswordBox that win provides or WatermarkPasswordBox that XCeedtoolkit provides generates an RoutedEventArgs so you can bind it.

    now in xmal view

    
    
            
    
                
    
                    
    
                
    
            
    
        
    

    or

    
    
            
    
                
    
                    
    
                
    
            
    
        
    

提交回复
热议问题