Elba Trams
Elba Trams

Reputation: 13

wpf skipping if even though condition is true

a simple IF function written for testing, the condition is clearly true, but it just skips to ELSE every time. Could somebody tell me if I'm doing something wrong?

namespace SANK
{
/// <summary>
/// Interaction logic for SignIN.xaml
/// </summary>
public partial class SignIn : Window
{
    string username;
    string password;
    string user = "user";
    string pass = "pass";
    public SignIn()
    {
        InitializeComponent();
    }

    private void LogInButton_Click(object sender, RoutedEventArgs e)
    {
        password = PassBox.ToString();
        username = UserBox.ToString();
        bool jednako = String.Equals(password, pass, StringComparison.OrdinalIgnoreCase);
        bool jednako2 = String.Equals(username, user, StringComparison.OrdinalIgnoreCase);
        if (jednako&&jednako2)
        {
            SignedIn.Visibility=Visibility.Visible;
            Application.Current.MainWindow.Show();
            this.Hide();
        }
        else
        {
            Wrong.Visibility = Visibility.Visible;
        }

    }
}

Upvotes: 0

Views: 76

Answers (3)

You can still use PaswordBox, but to get text from Passwordbox you have to use this:

password = PassBox.Password;

Upvotes: 0

Ahmed Bettaieb
Ahmed Bettaieb

Reputation: 74

You should not call toString method on a class the output of password & username

password = PassBox.Text;
username = UserBox.Text;

are "System.Windows.Controls.TextBox" which doesn't make any sense!! In order to access to the value of textbox you need to call TextBox.Text property.

Happy Coding

Upvotes: 1

d.moncada
d.moncada

Reputation: 17402

Are you using TextBoxes? If so, change it to use the .Text property:

password = PassBox.Text;
username = UserBox.Text;

Upvotes: 5

Related Questions