by kirupa |
20 August 2007
In the previous
page, you finished working on the interface. The interface is only a part of
an application. The other part is the application logic, and this page will get
you started towards adding the code needed to make your great-looking actually
do something useful!
The application logic is the code that makes your
application actually do something. So far, you've primarily
focused on the user interface side of things. With the
application logic, we delve into Visual Studio and C# with a
dash of Blend here and there for building bridges between
the designer and developer realms.
What we want to do is have our application read aloud
the text you input into the textbox. That will be
accomplished by you clicking on the Speak button. To do
that, we need to add an event handler that does something
when your Speak button is clicked.
In Blend, select your Speak button. From the Properties
pane, to the right of your Name field and Properties button,
you'll find the Events button:
[ click on the Events button to access tie events to event
handlers ]
Click on the Events button to display a list of events
your selected button supports. The first event listed should
be the Click event:
[ the event we are interested in is the Click event ]
Click on the textfield to the right of the Click event to
specify the name of your event handler. Give your event
handler the name Speak:
[ in the Click event's textfield, enter the world Speak ]
Once you have given your event handler the name Speak,
press Enter. After a brief second of what seems like frantic
computer activity, Visual Studio / Express will launch. You
may receive a security warning, and if you do, select the
Load project normally option:
[ if prompted about opening a project created externally,
choose the Load project normally option ]
The end result in most cases will be that you will see
the event handler code snippet displayed for you in Visual
Studio or Visual C# Express:
[ the Speak event handler has automatically
been created for us ]
Great! In this section you bound an event to an event
handler. To learn more about what that means, read my
Event Handlers in WPF tutorial. To look at the end
result, when somebody clicks on your Speak button, the Speak
method (what you see in Visual Studio) will be called. Let's
now proceed to the
next page and look at how to make our Speak method
actually say something out loud.
Onwards to the
next page!
|