Thursday, September 23, 2010

Working with Silverlight

Here are some examples of integrating silverlight and javascript





Add this reference to your code behind

using System.Windows.Browser;

Simple call :

private void btnFonctionJs_Click(object sender, RoutedEventArgs e)

{

HtmlPage.Window.Invoke("AfficheMessage");

}
Call with parameters

private void btnFonctionJsParam_Click(object sender, RoutedEventArgs e)

{

HtmlPage.Window.Invoke("AfficheMessageParam", new string[] { "Salut!" });;

}

call with anonymous javascript function

private void btnJsInline_Click(object sender, RoutedEventArgs e)

{

HtmlPage.Window.Eval("(function(){ alert('Fonction anonyme Js inline depuis Silverlight 2'); })()");

No comments:

Post a Comment