SIGN UP MEMBER LOGIN:    
ARTICLE

How to access LightSwitch methods from Silverlight Application: Part III

Posted by Jaganathan Bantheswaran Articles | VS LightSwitch 2011 September 01, 2011
In this article, we shall discuss how to access the Methods of LightSwitch from Silverlight Application using button Interaction triggers in Xaml.
Reader Level:

Prologue:

In this article, we shall discuss how to access the Methods of LightSwitch from Silverlight Application using button Interaction triggers in Xaml.

Let us create a demo Visual Studio LightSwitch 2011 application to explain the above point.

Preparing LightSwitch Solution:

Start the Visual Studio LightSwitch 2011; create a LightSwitch project as shown in the below figure.

 Preparing LightSwitch Solution

In this demo application, we will simply define a method to say Hello to world when we click on a Silverlight button control.

Designing Entity:

As we are simply saying hello to world, we don't need an entity.

Designing Screen:

Create a Search Screen as show in the figure given below.

 Preparing LightSwitch Solution

Here,

  1. Select the "Search Data Screen" template from the   Screen template panel.
  2. 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.

Adding LightSwitch Method

Here,

Open the screen designer then,

  1. Click on the "Add Data Item..." button, which is at the top of the screen designer.
  2. It will show a dialog box. In that, select the "Method" option from the "Screen Member Type" group.
  3. Give the method a name like "SayHello" and click on OK.

Editing the Method:

Editing LightSwitch Method

Here,

  1. 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.
  2. From the Right click option, select "Edit Execute Code" which will create a method like below one.

Editing LightSwitch Method

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.

Creating Silverlight Button Usercontrol

Xaml for the Usercontrol:

As we said, we are going to call the LightSwitch method from Silverlight Xaml page.

Xaml for the Usercontrol

Here,

  1. Include the namespaces for the interaction triggers and CallMethodAction.
  2. Implement the event trigger.
  3. 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 Silverlight project.

Xaml for the Usercontrol

The Interaction and Interactivity namespaces has the elements for the button event triggers.

It is important to build the Silverlight Application to generate the required dlls.

Adding Silverlight Button Usercontrol to LightSwitch App:

Adding Silverlight Button Usercontrol to LightSwitch App

Click on the "New Custom Control" option to add the Silverlight control.

Adding Silverlight Button Usercontrol to LightSwitch App

Here,

  1. Click on the "Add Reference" button to point to the Silverlight button control dlls.
  2. After pointing to Silverlight user control dlls, just click on "Main Page".
  3. 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:

Adding Silverlight Button Usercontrol to LightSwitch App

When you click on the Say Hello button, you will get a Message box saying "Hello".

Summary:

In this article part, we have seen how to call Visual Studio LightSwitch 2011 application methods from Silverlight Application using Xaml button event triggers.

Thanks for spending your precious time here. Please provide your valuable feedbacks and comments, which make me give a better article next time.
 

Login to add your contents and source code to this article
share this article :
post comment
 

Thanks to all....

Posted by Jaganathan Bantheswaran Sep 02, 2011

Nice article,Thanks

Posted by Alok Pandey Sep 02, 2011

Jaganathan, This is a great primer on how to extend LigthSwitch applications with our own code. Thanks!, ~Dan

Posted by Dan Sullivan Sep 01, 2011

Good article. Thanks

Posted by Rohatash Kumar Sep 01, 2011
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Nevron Gauge for SharePoint
Become a Sponsor