We should only show the login button or we should only activate the login button, make it clickable
when a password is entered.
Now, unfortunately, the password box that we have right here, right.
And its property that we're using here, the password, we cannot really use it for data binding immediately
because of security and privacy considerations, but we can well use a workaround and go to our login
view example here.
Password box and use the password changed property or event.
Sorry, it's not a property, it's an event.
So password box, let's say password changed.
There we go.
You can see it's indicated by a nice lightning strike, right?
That's an event password changed and we can just create a new one as we did with the login button.
We can say password box, underscore password change, for example, that would be a good name or it's
really up to you.
We could also say on password changed.
I like that one more.
The on password changed even though it does not really name the actual element it's related to on password
changed.
Great.
So again, we copied it over and we take it to our login view code behind file right here.
So we create a new public void on password changed.
Open up the parentheses right on object sender event args e right.
And now we can simply say that our button that we got right here.
Button right.
Let's give it a name so that we can actually call it, let's say name X or X name.
Let's set it to login button, save it like this.
Go back to the code behind You can say login button.
Dot is enabled.
You got that right here.
We will now toggle it depending on the password change event so that on password change event will get
triggered whenever we will change the value inside of the password box.
Right.
So login button is enabled equals to when we do not have a null or empty string.
So we do say like not right.
So write down the exclamation mark and we say string dot is null or empty.
You can say password, box dot password.
You can see that right here.
I will just resize that so that it is really depending on the value of the password box.
So if the value is null, it will be disabled.
If it's not null, it will be enabled.
Now if you're clever enough, you will know now that even though when we start the application in the
password box is empty, the login button will still be enabled because the on password will not got
triggered so far.
Right?
It will still be active.
But if we now say Jay, for example, and I remove that it will go away because it checks every time
I write down something.
It checks.
Yeah.
Does it have a value?
If yes, enable it.
But if I remove everything, it still gets triggered all the time.
And now it's like, no, it's empty.
I will disable it, but we for sure want to have it well disabled from the very beginning.
So what we can do is we can simply go to our login view example, take our login button here, right,
open up our properties and then resize the window so that you can see it better.
Scroll a little bit down and untick the is enabled box or simply go to the button definition here and
set is enabled to false.
So by default the password box will be empty.
So we can also deactivate or disable our login button.
But now if I write down test for example, you can see that we can enable it and if I remove that.
We're not able to log in because there is no value entered.
That's nice.
Well, this is a great design philosophy when it comes to the user experience side of you.
Cool.
Now let's disable that.
And this is how you can actually check if the user has entered the value and then use that state to
enable or disable something using an event which is called change, which will always get triggered
in the moment when we adjust the content of the specific element.