How to: Handle Silverlight Screen Events
You can customize your application by writing code that runs when certain events happen. For example, you can write code that runs before data is saved to a data source.
The events you can handle can be grouped into four categories:
Button methods that are called when a button is clicked.
General methods that are called when data is loaded or saved, or when a screen is closed.
Access control methods that are called to verify if a user has permission to perform a task.
Collection methods that are called when a collection is modified.
A description of these methods appears in the tables at the end of this topic.
To handle a screen event
Open the screen that you want to modify by double clicking it in the Solution Explorer.
The Screen Designer opens.
At the top of the Screen Designer, click the arrow next to the Write Code button, and then select a method. The methods to which you can add custom code appear in the tables below.
The Code Editor opens.
The Collection Methods only appear in the Write Code drop-down list if the collection is selected from the left data pane in the Screen Designer.
Place your cursor in the method that was just created and type the code that you want to run when the event occurs.
The following table lists screen-related event methods. All of these methods run on the client tier.
Called when the button associated with the method is clicked.
Called just after a screen is activated.
Called just before the screen closes.
Called just after the screen appears.
Called just before the screen data is retrieved.
Called when a request is made to display the screen.
Called when attempting to save the screen results in an error.
Called just after the screen is saved.
Called just before the screen is saved.
Access Control Methods
Called before a screen appears. LightSwitch calls this method to check permissions for the current user.
Called before a method is runs. LightSwitch calls this method to check permissions for the current user.
Called just after the collection has changed.
Called just after the currently selected item in the collection is selected.