Introduction
29/72010: Sorry but I am going to be dropping this series because my software focus has change to developing Windows Phone 7 applications. Maybe re visit this in the future (hopefully before CRM 5 is released 
Hi, this is part 1 of a series of posts giving an introduction to extending Microsoft Dynamics using Silverlight.
In this post I will outline how to add a custom Silverlight control to any of the entity forms.
For these articles I will be using Visual Studio 2010 Professional with All of the usual Silverlight (version 4) tools installed.
At Sequence the company where I work we make use of the eService accelerator this allows our customers to log cases via an extension to our web site. For this series of posts I am going to create a new tab in the contact entity screen that will display details of the contacts log in details that are stored in a separate ASP.NET authentication database.
How it works
The CRM 4 entity forms allow administrators to customise forms in many different ways but the one way that makes things handy for us is the ability to add IFRAME elements into a form. We will use this customisation to display a Silverlight control inside the form.
Getting Started
Create a new Silverlight application as normal ensuring that you enable RIA services and create a test web project.
NOTE: In future when you will want to make this live you will need a server available that you can add the .Net framework 4 and host the web site or virtual directory.
Identifying the Entity
So that the Silverlight application knows what entity it is using it will need to be passed the Id of the entity that is being displayed in the entity form. To ensure that this works when you add an IFRAME customisation to an entity you will need to ensure that the I frame is passed the record ID and type:

This results in the following URL:
http://localhost:40363/ContactDashboard.aspx?type=2&typename=contact&id={299390EB-049E-DE11-A280-00155D801211}&orgname=Sequence&userlcid=1033&orglcid=1033
To get these values into my Silverlight application I have decided to use Silverlight parameters. To do this I first added the following code to the ASPX page that displays the application:
public string SilverlightParams
{
get
{
string sRes = string.Format("id={0},type={1},orgname={2},typename={3}",
Request["id"], Request["type"], Request["orgname"], Request["typename"]);
return sRes;
}
}
Then in the page mark-up I added the following to the params for the Silverlight application:
<param name="initParams" value="<% = SilverlightParams %>" />
So we get this:
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2"
width="100%" height="100%">
<param name="source"
value="ClientBin/Sequence.CRM.SilverlightExtensions.MainDashboard.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="4.0.50303.0" />
<param name="autoUpgrade" value="true" />
<param name="initParams" value="<% = SilverlightParams %>" />
<a href=http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50303.0
style="text-decoration:none">
<img src=http://go.microsoft.com/fwlink/?LinkId=161376
alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
Making the App Know the entity Id
In the Silverlight application project I added the following to the App class code:
private Guid? m_ContactID = null;
public Guid? ContactID
{
get
{
return m_ContactID;
}
}
In the Application_Startup method:
private void Application_Startup(object sender, StartupEventArgs e)
{
if (!string.IsNullOrEmpty(e.InitParams["id"]))
m_ContactID =
new Guid(e.InitParams["id"]);
this.RootVisual = new MainPage();
}
We can now access the ContactID anywhere in the code like this:
((
App)App.Current).ContactID
Just checking
Here is a screenshot of a simple app in an I frame just to show it works:
In part 2 I will show how to hook this app up to the ASP.NET authentication database.