开发者

MVVM and password

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜