How to: Handle Silverlight Screen Events
For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.
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.
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.
|<MyMethodName>_Execute||Called when the button associated with the method is clicked.|
|<ScreenName>_Activated||Called just after a screen is activated.|
|<ScreenName>_Closing||Called just before the screen closes.|
|<ScreenName>_Created||Called just after the screen appears.|
|<ScreenName>_InitializeDataWorkspace||Called just before the screen data is retrieved.|
|<ScreenName>_Run||Called when a request is made to display the screen.|
|<ScreenName>_SaveError||Called when attempting to save the screen results in an error.|
|<ScreenName>_Saved||Called just after the screen is saved.|
|<ScreenName>_Saving||Called just before the screen is saved.|
|Access Control Methods||Description|
|CanRun<ScreenNam||Called before a screen appears. LightSwitch calls this method to check permissions for the current user.|
|<MyMethodName>_CanExecute||Called before a method is runs. LightSwitch calls this method to check permissions for the current user.|
|<CollectionName>_Changed||Called just after the collection has changed.|
|<CollectionName>_SelectionChanged||Called just after the currently selected item in the collection is selected.|