Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Silverlight (XAP) Web Resources

[Applies to: Microsoft Dynamics CRM 2011]

Microsoft Silverlight web resources provide a great way to include highly interactive custom user interface components in Microsoft Dynamics CRM.

Microsoft Dynamics CRM 2011 support adding Silverlight 4.0 web resources to entity forms. You can display Silverlight 5.0 web resources within an HTML web resource using a hosting <object> element that is configured for that version.

  • Microsoft Silverlight web resources cannot be viewed in the 64-bit version of Microsoft Office Outlook.

  • To display a Silverlight web resource outside an entity form or chart, create an HTML web resource to be the host page for the Silverlight web resource. Then use the $webresource: directive to open the HTML web resource.

Creating Silverlight Web Resources

Silverlight web resources are easily created using the web resource form by entering a name, a display name, selecting Silverlight (XAP) as the type, and uploading the .xap file. The web resource must be published before you can use it. However, because Silverlight web resources typically provide some interaction with contextual data in Microsoft Dynamics CRM, you should plan how you create your web resources.

Accessing Context data

When you use the Preview button in the web resources form or just browse to the URL provided, the Silverlight application is hosted in a generic HTML page without context information. If your Silverlight application does not require contextual information, you can use this URL to view your Silverlight web resource.

If you do require contextual information, you must either:

  1. Add your Silverlight web resource to an entity form.

  2. View your Silverlight web resource using an HTML web resource configured to provide context information.

If your Silverlight web resource is designed to be viewed in an entity form, the form has an Xrm.Page.context object you can use to access contextual information.

If you need your Silverlight application to appear outside the context of the form you must configure an HTML web resource to provide this context information by adding a reference to the ClientGlobalContext.js.aspx page. After this reference is added, your Silverlight application can access contextual information in the same way it can in an entity form. The following sample shows how to call the getServerUrl function from the Xrm.Page.context object.

private string serverUrl = "";
ScriptObject xrm = (ScriptObject)HtmlPage.Window.GetProperty("Xrm");
ScriptObject page = (ScriptObject)xrm.GetProperty("Page");
ScriptObject pageContext = (ScriptObject)page.GetProperty("context");
serverUrl = (string)pageContext.Invoke("getServerUrl");

Passing Data from a Form to an Embedded Silverlight Web Resource

When you add a Silverlight web resource to a form you can select the Pass record object-type code and unique identifier as parameters option. You also have the option to enter text as a custom parameter.

These values are passed to the Silverlight control as a InitParams, a dictionary of key/value pairs.

The values passed are described in the following table.


Key Description


The unique identifier of the record.


The entity type code. For custom entities this can vary between organizations.


The logical name of the entity.


The name of the organization.


The language code representing the user’s language preference.


The language code representing the organization’s base language.


The value of the text entered as a custom parameter.

These values can be accessed at run time using the syntax in the following example:

string entityTypeName = App.Current.Host.InitParams["typename"];

Writing and Testing Silverlight Web Resources

If your Silverlight web resource is independent of any contextual data from Microsoft Dynamics CRM, you can write and test your Silverlight application as you typically would. After you create a new web resource by uploading your .xap file, you can test it by using the Preview button in the web resource form after you have saved and published the web resource.

However, it is more likely that your Silverlight application has contextual data dependencies that cannot be fully simulated outside of Microsoft Dynamics CRM.

The process of creating a Silverlight web resource that includes form or context dependencies is as follows:

  1. Create your Silverlight application project.

    You should select to create a web application with your project.

  2. Write and test as much of the application as you can without requiring contextual data from Microsoft Dynamics CRM.

  3. Create web resources by uploading the .xap and .htm files as Silverlight and HTML web resources.

  4. Write code in your Silverlight application project.

  5. Build your Silverlight application project.

  6. Upload the built version of the .xap file from the web application project ClientBin folder to update the Silverlight web resource you created in step 3.

  7. Test your Silverlight web resource by either:

    • Viewing it using the Preview button of the host HTML web resource you created.

    • Viewing it in the context of an entity form that you have added it to.

      Use this option is your Silverlight application has dependencies on Form elements or context information.

  8. Repeat steps 4 through 7 until you are finished.

When you want to show a Silverlight web resource outside of an entity form, for example in the application main frame by editing the Site Map, you must provide a webpage (HTML) web resource to act as the host for the Silverlight web resource.

Never edit the HTML source code for a page hosting a Silverlight web resource using the text editor provided in the application. The text editor changes the HTML and breaks <object> element definition necessary to host the Silverlight XAP web resource. For more information, see Using the Text Editor for HTML Web Resources.

If you must use the text editor, omit the data="data:application/x-silverlight-2," parameter in the <object> element. Although this should prevent breaking the Silverlight web resource, the text editor may still introduce other undesirable changes.

Debugging Silverlight Web Resources

Silverlight web resources that do not rely on contextual data from Microsoft Dynamics CRM can be debugged in Microsoft Visual Studio. However, if the Silverlight web resource requires contextual data to perform the functions, you will have to use a different procedure.

  1. Build your Silverlight application.

  2. Upload the built version of the .xap file from the web application project ClientBin folder.

  3. View your Silverlight application in the context it is designed to be used in.

  4. In your Silverlight application project, from the Visual Studio menu, select Debug and then Attach To Process.

  5. In the Attach to Process dialog box, find an iexplore.exe process where the Type column value is Silverlight, x86.

  6. Select that process and press Attach to close the dialog box and start debugging.

  7. In your Silverlight application project, set a breakpoint.

  8. Refresh the browser window or, in the Silverlight application, perform the action that you need to test your code.

See Also

Microsoft Dynamics CRM 2011
Send comments about this topic to Microsoft.
© 2013 Microsoft Corporation. All rights reserved.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.