Did You Know… There are two ways to pass data to your Silverlight 1.0 control on creation

CreateSilverlight() and its wrapper, CreateSilverlightEx() both take an optional sixth and seventh parameter. The sixth, initParam takes a string parameter that you can easily fetch in your javascript code; it becomes an attribute of the Silverlight control (plugin) itself.

For example, you can modify the starter sample that Visual Studio 2008 creates for you by adding this line to Default.html.js:



The sixth parameter must be a string. How you use that string is entirely up to you.  . To see using this parameter at work, modify HandleMouseUp in  Scene.xaml.js as follows:

handleMouseUp: function(sender, eventArgs) 
    var mouseUpAnimation = sender.findName("mouseUp");
var paramValue = this.plugIn.initParams; alert(paramValue); }

In this case, you're accessing the value of the parameter passed in by the user, and placing it into the alert box when the button is clicked.



About Jesse Liberty

Jesse Liberty has three decades of experience writing and delivering software projects and is the author of 2 dozen books and a couple dozen Pluralsight & LinkedIn Learning courses. He was a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a Xamarin Certified Mobile Developer and a Xamarin MVP and a Microsoft MVP.
This entry was posted in z Silverlight Archives. Bookmark the permalink.