开发者

MVVM and password

开发者 https://www.devze.com 2023-01-10 05:30 出处:网络
I\'m using MVVM and the model has password field. From what I\'ve found on web, when handling this password you must implement custom class for binding and use PasswordBox. I think this is overhead. C

I'm using MVVM and the model has password field. From what I've found on web, when handling this password you must implement custom class for binding and use PasswordBox. I think this is overhead. Could you point me to a better w开发者_如何学运维ay to using the add/edit usercontrols connected to a viewmodel with password?

Thank you


Easy way but not MVVM:

Xaml

<PasswordBox PasswordChanged="PasswordBox_PasswordChanged"

Xaml.cs

private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
{
    if (viewModel != null && sender is PasswordBox)
        viewModel.DatabasePassword = ((PasswordBox) sender).Password;
}

private void Load()
{
    //Fills viewModel.DatabasePassword
    viewModel.ReadData();

    PasswordBox.Password = viewModel.DatabasePassword;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消