Content Index Search
 

Event handling

Microsoft® Expression Blend™ is an excellent tool for developing rich Windows®-based applications and user interfaces (UIs) that can interact with user input. For example, if you want your application to start an animation timeline that moves a ball when a user moves the mouse, Expression Blend has features that you can use to configure that relationship. You can also configure your application to respond to changes in the application state itself.

There are two methods that you can use in Expression Blend to make your application respond to user input and application changes:

For a list of events that you can hook up to, either by using triggers or by using event handler methods, see Events quick reference in this User Guide.

Hooking up to event handler methods

Expression Blend helps you to write event handler methods, by generating the code for empty methods. If you have Microsoft® Visual Studio® 2005 Standard Edition or later installed, Expression Blend will open your project in Visual Studio 2005, will open the code-behind file, and then will paste in the empty event handler method. If you do not have Visual Studio 2005 Standard Edition or later installed, Expression Blend will copy the empty event handler method to the Clipboard so that you can manually open the code-behind file and paste the method in. For more information, see Create a new event handler method in this User Guide.

Expression Blend was designed with team development in mind. Often, software teams are made up of designers who work on the UI and programmers who work on the code that runs behind the UI. You might receive an altered code-behind file from a developer who has added various event handler methods for you to hook into from the UI. You can do this in Expression Blend. For more information, see Hook up an existing event handler method.

Programming issues

Experience with programming Windows-based applications is useful when you are writing event handlers. This is because of the Windows Presentation Foundation (WPF) threading model and the timing of UI rendering. For example, if you create an event handler method that updates the text that is displayed in a Label, performs some other calculations, and then updates the text in the same Label again before the event handler method completes, you will only see the last update. This is because the rendering of your UI occurs at the end of your event handler method and all processing is done on the same thread, so your application cannot take time out during the execution of your method to update the UI. For information about how to write WPF applications that have multiple UI updates and calculations, see the Threading Model topic in the WPF section of MSDN.