tags:

views:

1396

answers:

2

I'm just getting started with M-V-VM and WPF and having issues understanding some binding issues.

I have a login page that has a ComboBox and PasswordBox. The ComboBox looks like this:

<ComboBox Name="comboBox1" SelectedItem="{Binding Path=Username}">

This works just fine - my values get updated everytime the SelectedItem changes on the ComboBox!

In my ViewModel I have an ICommand which uses this method to determine if the Login button is active:

public bool CanLogin()
{
    return !string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password);
}

So my problem is I don't have the PasswordBox bound to the Password property on the ViewModel - so I have no way to tell when it is updated.

So how do I get the value of the PasswordBox to my ViewModel? Everything I've read just says don't bind a PasswordBox for security reasons. I would simply take off the password restriction on the CanLogin() but I need the value to pass along to an AccountService.

+4  A: 

Hi

Interesting.

look at this blog post and see if it is helping you. http://blog.functionalfun.net/2008/06/wpf-passwordbox-and-data-binding.html

Ariel

ArielBH
Thanks - It seems like it should be a little easier than that - but it worked!
djschwartz
+1 That link solved my problems perfectly! Thanks!
Giffyguy
A: 

I posted a GIST here that is a bindable password box.

Taylor Leese