Compartilhar via


How to: Add a Custom Command to a Silverlight Screen

You can add custom code that runs when the user clicks a button on a screen. First, add a custom command to a screen. Then, add custom code that runs when the user clicks the button.

To add a custom command to a screen

  1. In the Screen Content Tree of the Screen Designer, decide where you want to place the command, and then perform one of the following actions:

    • Right-click the desired node, and then select Add Button.

    • Select the desired node. Then, on the command bar of the Screen Designer, click Add Layout Item, and then click Button.

    The Add Button dialog box appears.

  2. In the Add Button dialog box, select one of the following options:

    • Select New Method if you want to create a method that runs when the user clicks the button.

    • Select Existing Method if you want to use a method that has already been added to the screen. You must select the method from the Name drop-down list.

  3. In the Screen Content Tree, right-click the command, and then click Edit Execute Code.

    The Code Editor opens and generates a method named ButtonName_Execute.

  4. Add custom code to the ButtonName_Execute method.

See Also

Other Resources

Screens: The User Interface of Your LightSwitch Application