1
votes

I want to be able to change the background color of the Entry field once data has been entered, so it would need to constantly check if the field is empty, but the code won't work for me as in the app doens't function and no button will work on it, "Name" is the name set on the Entry field in the XAML file.

public void BackgroundColourEntry()
    {
        while (true)
        {
            if (Name.Text != "" && ClientName.Text != null)
            {
                Name.BackgroundColor = Color.FromHex("#2c3e50");
            }
        }
    }
1
Please state what it means when you say it doesn't work for you, Do you get a wrong output? error?BlooB

1 Answers

2
votes

You can test the contents the Entry in the TextChanged entry.

Example:

BackgroundColourEntry.TextChanged += (sender, e) => 
{
    var entry = sender as Entry;
    if (string.IsNullOrEmpty(entry.Text))
    {
        entry.BackgroundColor = Color.Red;
    } 
    else
    {
        entry.BackgroundColor = Color.Green;
    }
};