Hello! Since there is no normal binding for PasswordBox, we had to do a binding through the command parameter for the button. As a result, the transfer from the view to the view model occurs through the method as follows:

Viewmodel

private void Auth(object parameter) { var passwordBox = parameter as PasswordBox; var password = passwordBox.Password; } public RelayCommand LoadedCommand { get { return loadedCommand ?? (loadedCommand = new RelayCommand(obj => { Auth(obj); })); } } 

View

 <Button Command="{Binding AuthCommand}" CommandParameter="{Binding ElementName=passwordBox}"/> 

Now I need to transfer any password value to PasswordBox in the view from the view model, how can I do this?

  • Theoretically, you can save the link to the PasswordBox in the VM and set the value there, but as for me this is a bad way. I don’t see another option to transfer the password from VM to V, relying on the code you provided - user227049
  • can you find out why you may need to transfer a password from VM to V? - user227049
  • Look here at this link: habrahabr.ru/post/215249 There, the binding is done differently, through the property VM. - foxhound
  • @foxhound no, you are confusing something - behavior added by reference - user227049

0