In this article, we shall discuss how to access the Methods of
LightSwitch from Silverlight Application using button Interaction triggers in
Let us create a demo Visual Studio LightSwitch 2011 application to explain the above
Preparing LightSwitch Solution:
Start the Visual Studio LightSwitch 2011; create a LightSwitch project as shown
in the below figure.
In this demo application, we will simply define a method to say Hello to world
when we click on a Silverlight button control.
As we are simply saying hello to world, we don't need an entity.
Create a Search Screen as show in the figure given below.
- Select the "Search Data Screen" template from the Screen template panel.
- As we have not designed an entity, simply select "None" from the "Screen Data" dropdown list.
Adding LightSwitch Method:
Add the LightSwitch method as shown in the below figure.
Open the screen designer then,
- Click on the "Add Data Item..." button, which is at the top of the screen designer.
- It will show a dialog box. In that, select the "Method" option from the "Screen Member Type" group.
- Give the method a name like "SayHello" and click on OK.
Editing the Method:
- In the "Screen Member Panel" which is at the left side of the screen tree. From this select the "SayHello" method and Right click it.
- From the Right click option, select "Edit Execute Code" which will create a method like below one.
It is important to build the LightSwitch
application to generate the required dlls.
Creating Silverlight Button Usercontrol:
Create a Silverlight Application as shown in the figure.
Xaml for the Usercontrol:
As we said, we are going to call the LightSwitch method from Silverlight Xaml
- Include the namespaces for the interaction triggers and CallMethodAction.
- Implement the event trigger.
- In the CallMethodAction element,
- MethodName property â€“ specifies the method to be called.
- TargetObject â€“ In which object the method is.
The above event trigger will trigger the
LightSwitch method when the user clicks on the button.
Before adding namespaces to the Xaml, we need to add the reference to the
The Interaction and Interactivity namespaces has the elements for the button
It is important to build the Silverlight Application to generate the required
Adding Silverlight Button Usercontrol to LightSwitch App:
Click on the "New Custom Control" option to add the Silverlight control.
- Click on the "Add Reference" button to point to the Silverlight button control dlls.
- After pointing to Silverlight user control dlls, just click on "Main Page".
- Let the Data for the control be "Screen".
We have successfully added the Silverlight user
control to LightSwitch application.
Hit F5 to see the Application in Action.
Application in Action:
When you click on the Say Hello button, you will get a Message box saying
In this article part, we have seen how to call Visual Studio LightSwitch
2011 application methods from Silverlight Application using Xaml button event
Thanks for spending your precious time here. Please provide your valuable
feedbacks and comments, which make me give a better article next time.