If you are using the Silverlight control within your form, you can use the following code within your Silverlight Application:
string accountId = App.Current.Host.InitParams["id"];
Make sure that on the form design, in the properties of the Silverlight control -> Formatting Tab check the "Pass record object-type and unique identifer as parameters".
You can also use the the dynamic object:
dynamic Xrm = (ScriptObject)HtmlPage.Window.GetProperty("Xrm");
var contactid = Xrm.Page.data.entity.getId();
Hope this helps.