Skip to main content
Home Forums Silverlight Programming Programming with .NET - General initParams in managed code
8 replies. Latest Post by jwilcox on June 21, 2007.
(0)
JasonLP
Member
16 points
14 Posts
05-24-2007 3:53 PM |
I've seen a few code samples on how to read initParams from javascript, but so far nothing from C#. In javascript, one would call sender.getHost() to get a reference to the SilverlightControl, and use that to read the initParams.
I can't find the equivalent in managed code. Any suggestions?
Thanks,
-Jason-
jwilcox
Participant
1082 points
187 Posts
06-19-2007 4:21 AM |
Give this a try:
A string dictionary is available in the current WebApplication instance:WebApplication.Current.StartupArguments
Namespace:using System.Windows;
Hope this helps,-Jeff
cyberdyme
24 points
7 Posts
06-19-2007 3:57 PM |
Jeff - This does not seems to work the dictionary for StartupArguments always seems to be empty
y_makram
Contributor
6172 points
1,233 Posts
06-19-2007 4:11 PM |
The access to the Silverlight host has been disabled for C# in the alpha release because of an issue related to Safari on Mac, it should be back in the next release. But you can access this value from JavaScript. Mark your class as scriptable, define an event and mark it as sciptable, register the instance of your class, and subscribe to the defined event. In the event handler get the Silverlight host and get the initparams. set initparams on your registered object.
I am in a hurry so there may be some ambiguity in what I say. If so please post a follow up question. If this is sufficient please select "mark as answer"
WJamesLord
138 points
118 Posts
06-19-2007 8:14 PM |
I think I have a solution. First, get the ID of the Silverlight control as detailed in the "How can I acquire the Silverlight HtmlElement control?" post (see http://silverlight.net/forums/t/2173.aspx). Then just invoke the following:
string params = HtmlPage.Document.GetElementByID(SilverlightId).GetAttribute("initParams") ;
06-20-2007 4:56 PM |
Yasser - What if you have multiple instances of the same silverlight control on a page.. (How will the Java script to manage code work)
06-20-2007 5:36 PM |
This will not be a problem. The event wiring will be instance specific. For example if you have two Silverlight controls with IDs control1, control2
You will first need to get a reference to the Silverlight control through getElementByID:
var control1 = document.getElementById("control1");var control2 = document.getElementById("control1");
Then wire to the control specific handler
control1.content.myScriptableObject.myEvent = handler1;control2.content.myScriptableObject.myEvent = handler2; This approach is useful if you need instance specific handlers. If all you needis to set the initparams of the right instance, this could be easily done by submitting the control instance as the sender parameter of the instanceIf this answers your question please select "Mark as Answer". If not please post a follow up question
luisabreu
1676 points
612 Posts
06-21-2007 5:06 AM |
hello.
well, i like the approach but i think that using events are overkill for this. I prefer to go with a property because it reduces the code I need to write.
06-21-2007 5:13 AM |
Could you share the CreateSilverlight JavaScript you're using, which includes the initParams, etc.? It should be a comma-deliminated list... I'd like to try to repro this on my Mac Mini... (I'm looking at the managed code WebApplication dictionary access, not the JavaScript solutions that've been discussed)
Thanks,Jeff