Image by Gojca via Flickr
The complete article at Dr.Dobb's journal here.
Must Read!
Image by Gojca via Flickr
Image via Wikipedia
Image via CrunchBase


<UserControl x:Class="JavascriptTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300"
Name="Xaml1">
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel>
<TextBox Name="NameTxt" Width="500" Height="20"></TextBox>
<Button Name="NameBtn" Content="Send to JS"></Button>
</StackPanel>
</Grid>
</UserControl>
namespace JavascriptTest
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
NameBtn.Click += new RoutedEventHandler(NameBtn_Click);
HtmlPage.RegisterScriptableObject("navObj", this);
}
void NameBtn_Click(object sender, RoutedEventArgs e)
{
HtmlPage.Window.Invoke("ExecuteAnimation", NameTxt.Text);
}
[ScriptableMember()]
public void SendMessage(string state)
{
MessageBox.Show("Message reached SL");
}
}
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>JavascriptTest</title>
<script type="text/javascript">
function ExecuteAnimation(params) {
loadexcel(params);
alert("Hello, World");
}
function load() {
var ctrl = $get("Silverlight1");
ctrl.Content.navObj.SendMessage('Hello');
}
function loadexcel(params) {
var ExcelSheet;
ExcelSheet = new ActiveXObject("Excel.Application");
ExcelSheet.Workbooks.Open(params);
//ExcelSheet.Visible = true;
// Place some text in the first cell of the sheet.
ExcelSheet.ActiveSheet.Cells(1, 1).Value = "This is column A, row 1";
// Save the sheet.
ExcelSheet.SaveAs("C:\\TEST.XLS");
// Close Excel with the Quit method on the Application object.
ExcelSheet.Quit();
// Release the object variable.
ExcelSheet = "";
}
</script>
<style type="text/css">
html, body {
height: 100%;
overflow: auto;
}
body {
padding: 0;
margin: 0;
}
</style>
</head>
<body >
<form id="form1" runat="server" style="height:100%;">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div style="height:90%;">
<asp:Silverlight ID="Silverlight1" runat="server" Source="~/ClientBin/JavascriptTest.xap" MinimumVersion="3.0.40307.0" Width="100%" Height="100%" />
</div>
<input type="submit" onclick="load()" />
<input type="submit" onclick="loadexcel()" />
</form>
</body>
</html>
