Geom dev Geom dev - 2 months ago 15
C# Question

Check if password field is empty

In my XAML I have:

<PasswordBox PlaceholderText="Password" Name="login_password" Width="350" />


Am trying to check if the
PasswordBox
is empty via:

if(login_password.Text == "") //this returns an error
{
//show message box
}


How can I check if the
PasswordBox
is empty?

Answer Source

The PasswordBox has the Password property. So you should check for Password property instead of Text:

if(login_password.Password == "")