All righty.
We are almost good to go to start working on our very first.
Well, let's say real application, even though the very first one will be very simple, but nonetheless,
it will still be fun.
Anyway, let me just remove the font size here because that's just not looking pretty nice.
Awesome.
What we want to do or what we want to take a look at in this video is we want to create a so-called
button event handler so that once we click on the button, we can execute some code.
And what you will also see is a small box called message box that we can display to show the user some
information.
Now we got our button right here.
What I want to do now is I want to remove inside of the code behind file.
I want to remove our second button.
It's just a demo project.
It's just for testing.
I want to keep it as easy as possible for you to follow along.
So I simply remove that.
We only need one button right now.
Here is our button.
Now let's define a click event.
Well, you probably already know at least something about events, right?
So sometimes we have classes and elements which offer us events.
So for a button, a pretty common event is the click event.
So once you click on a button, an event will get started and well, the attached code will get executed.
Let's say it that way or the attach listener to be more specific.
So the way we can do that is to check for the click event here.
And it's always indicated by a little lightning strike.
So let's click on, click right here, double click on that.
And now we can create a new event.
Handler Let's just do that.
Let's just click on new event.
Handler.
You can now see that he has put in a name which is called button Underscore Click.
So he has pretty much just combined the button tag name itself and the click event name to create that
name.
Now let's switch over to our code behind file.
And as you can see here, we got a new private void that got created for us, which is, well, the
attached listener.
So in the moment we click on our button inside of the user interface, this event or this method right
here will get called.
We will get the reference to the object that started the event.
So in that case, it is our button.
We can access it using the sender and we also get some routed event arcs right here.
So in the moment when we click on that button, in this method, this event handler will get called
or invoked.
We want to show a message box.
So call the message box and then show and let's say Hello world.
So this is how you can specify an event.
Well, at least the click event for a button.
We have our button, we have a click event and we have attached a new name, which is, well, the actual
event handler.
And then with the same name we have a private void button, click and then the sender and all of that.
So we could also just debug the code and take a look at the sender object.
But anyway, let's just start our application right now and smash that button to see the message box.
There we go.
Let's click on the A button and as you can see, a message box appears and shows Hello World.
So this is the actual proof that our event handler works.
Now if we rename that and say button click to try to start our application, you can see that there
are build errors.
So that does not work because the actual connection between the click event that is specified here.
So the event handler does not work anymore.
So the button click method which is referenced here, does not exist anymore because it's called button
click to now.
Now we could set up all of this manually from scratch for sure.
We could say button click to and then it will be linked to this button.
Click here.
If we start our application, it will work again.
Awesome.
So yeah, that's very important because it gives us the possibility to well, let the user perform some
actions in the user interface.
Let's say click on a button, write down some text in a box, and then click on a button, remove something
or whatever, and we can assign handlers.
So event handlers, which will get invoked in the moment, the action will get performed, let's say
a button click or whatever else we could think of, and now we can get started and create our very first
small application.
So I'm excited.
I hope you are too.
So I see you back in the next lecture.