Skip to main content
Home Forums General Silverlight Hosting and Streaming Passing InitParams through the <OBJECT> tag...
11 replies. Latest Post by ebirrell on June 12, 2008.
(0)
BlueAqua...
Member
57 points
37 Posts
04-24-2008 8:00 AM |
Hi there,
on page http://msdn2.microsoft.com/en-us/library/system.windows.startupeventargs.initparams(VS.95).aspx, it says that "The initialization parameters are passed as the initParams parameter of initialization functions such as Silverlight.CreateObject or Silverlight.CreateObjectEx, or potentially set directly on the OBJECT/EMBED tag."
All my attempts to pass parameters through the <OBJECT> tag fail. Does anyone have a working code sample?
I am working with Silverlight 2.0. If this is not yet implemented in the current version of Silverlight, does anyone know when it will be implemented?
Can anyone help?
A
mchlsync
Star
14566 points
2,730 Posts
04-24-2008 10:55 AM |
Can you show us the code that you wrote?
If you read this "Instantiating a Silverlight Plug-In (Silverlight 2) " from Silverlight doc, you should be able to pass the initparams through the <OBJECT>
I just tested it. It is working fine..
SilverlightApplication8TestPage.html
<body> <!-- Runtime errors from Silverlight will be displayed here. This will contain debugging information and should be removed or hidden when debugging is completed --> <div id='errorLocation' style="font-size: small;color: Gray;"></div> <div id="silverlightControlHost"> <object data="data:application/x-silverlight," type="application/x-silverlight-2-b1" width="100%" height="100%"> <param name="source" value="ClientBin/SilverlightApplication8.xap"/> <param name="onerror" value="onSilverlightError" /> <param name="background" value="white" /> <param name="initParams" value="color=white" /> <a href="http://go.microsoft.com/fwlink/?LinkID=108182" style="text-decoration: none;"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/> </a> </object> <iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe> </div></body>
App.xaml.cs
private void Application_Startup(object sender, StartupEventArgs e) { this.RootVisual = new Page(); var color = e.InitParams["color"];}
04-24-2008 12:00 PM |
Thanks for your help. This really works. The mistake which I have made was that I did not use the equal sign ('=') within the initParams definition. Stupid mistake.
04-24-2008 12:08 PM |
BlueAquarius:Thanks for your help. This really works.
Your welcome. Please mark my post as an answer if it's helpful.
ebirrell
8 points
13 Posts
06-11-2008 8:45 PM |
I'm trying to do exactly this and it isn't working. I've tried just copy-pasting the code from your previous post, and I get the same response: e.InitParams.Count = 0.
Any ideas what might be going on?
Thanks
06-11-2008 11:04 PM |
Can you please share your code (the HTML Page with the <OBJECT> tag as well as the App.cs file).
06-11-2008 11:07 PM |
... and which version of Silverlight are you using? Last Friday, a new version (Silverlight 2.0 Beta 2) came out.
06-12-2008 12:49 PM |
I believe I'm using Silverlight 2 Beta 1. I got it two weeks ago.
I'm just trying to get the example from above to work. Here is the html I'm using: (sorry about the lack of indenting)
<
<!-- saved from url=(0014)about:internet -->
html, body {
height: 100%;
overflow: auto;
}
body {
padding: 0;
margin: 0;
#silverlightControlHost {
</
This will contain debugging information and should be removed or hidden when debugging is completed -->
And here is the App.xaml.cs file:
using
{
InitializeComponent();
html, body { height: 100%; overflow: auto; } body { padding: 0; margin: 0; } #silverlightControlHost { height: 100%; } function onSilverlightError(sender, args) { if (args.errorType == "InitializeError") { var errorDiv = document.getElementById("errorLocation"); if (errorDiv != null) errorDiv.innerHTML = args.errorType + "- " + args.errorMessage; } }
06-12-2008 1:26 PM |
ebirrell,
thanks for sharing your code. However, from your code I am not able to understand the following:
06-12-2008 5:14 PM |
1) It compiles. However, when I try to run this code, it throws a KeyNotFound exception on the line var color = e.InitParams["color"] (and the VS debugger says that the dictionary e.InitParams has zero keys). I do not know why it didn't put the color key in the dictionary or how to fix it (or get anything else to go into the dictionary).
2) I expect my application to load a blank page. (As you said there isn't much code, I'm just trying to isolate the problem). However it just gets as far as the line var color = e.InitParams["color"] and throws the exception.
3) Quite possibly. I'm new to both of them. If you can suggest a valid line of C# code that will access the value of any key in e.InitParams, that would be great.
Thanks again for your help!
06-12-2008 6:00 PM |
I do not really see why it would not work. The only thing which I wouldchange is convert var to String. But that's just a personal preference.
But here is another questions.... Are you absolutely sure that when you execute your project, you definitely run the HTML Code which is pasted above? When you create a Silverlight application in Visual Studio, the template creates two test pages for you: an HTML Page and an ASPX page. maybe you have added the line <param name="initParams" value="color=white" /> to the HTML Page and then execute the ASPX page.
To be absolutely sure: right-click on the HTML page and select 'View in Browser'.
06-12-2008 6:43 PM |
Ah, you're right. I didn't notice that.
Thanks!