|
|
The Crapazoids
This article may be obsolete given the May 2007 Silverlight 1.0 beta release, I
haven't explored it fully. After a change to the script created, it works
like a charm.
I created a user control to counter one of my major handicaps, memory. Specifically I have a hard time keeping straight all the APIs that I encounter.
Like many .NET developers I would be lost without Intellisense. One
of the nice things about the User Control is that you have Intellisense for all the
public properties of that control, when in the asp source view of a parent page.
Much like you would for any other control's attributes.
Taken directly from a new silvelight project , this is the javascript that you would
need to add to every page to create the ActiveX control:
It really isn't too much script, however it does get in the way after a while.
Especially with 2 or 3 controls on a page. That and I dont like cut and pasting
the block from one place to another, looking at the comments to remember which param
is what... The new Silverlight project does organize this alot better.
To start off I created an ascx control in the web project.
All Silverlight controls need a tag to live in, so I created a DIV in the
Source of the .ascx. The source of the .ascx looks like so:
And initially the code behind is pretty simple:
We can't add the javascript to create the Silverlight control in the ascx source,
because the ID of the DIV tag will be prefixed when the control is added
to a parent page.
So instead we put the Javascript we need in the code behind and register it
with the parent page.
Now we could just concat a large string and use Page.RegisterStartupScript
in the page load and call it a day. But we will want to be able to configure
the Silverlight control at design time without hacking away at the code that generates
the script. So we create public properties on the User Control to expose the
most commonly used params for the ActiveX control. Then use those to create
the javascript.
Once the Control is built (rebuild the project) you can then use it on a parent page. You will need
to register the control on the page. But after that its reuse all the way.
Example use:
One last thing. In order to create the host Silverlight control, you need
to load the Silverlight.js file. I have it in the header of my master page.
However you can put it almost anywhere, the ascx source, the parent page or the
codebehind. I recomend the parent page or a Masterpage.
|
|