Behold the turtle

jb's Blog

"behold the turtle, he only makes progress when he sticks his neck out"
Combine your HTML with .NET using Silverlight 02 May 2007 13:33

As I mentioned yesterday I think the major announcement around Silverlight is the integration with the "CoreCLR". Scott thinks so also (see 2a and 4).. btw thats a post worth reading..

So ignoring all the UI goodness for a few moments, lets imagine I just want to avoid using all that nasty JavaScript and would rather use C# in the browser. Well why not just create an empty transparent canvas and use Silverlight as a .NET hosting container?

A contrived example of how this works in practice is:

Create a simple HTML page:

<div id="fooBlock">Hello World</div>

Add in a Silverlight code container block, and our associated XAML with a Canvas on it, in my case I decided to host an Image inside the Canvas for good looks..

    <div id="SilverlightControlHost" >
        <script type="text/javascript">
            createSilverlight();
        </script>
    </div>

the CreateSilverlight call just instantiates a new XAML object which is hosting Page.xaml. Note the property set of enableHtmlAccess to true which allows the managed instance to get access back to the client side DOM.

Sys.Silverlight.createObjectEx({
  source: "Page.xaml",
  parentElement: document.getElementById("SilverlightControlHost"),
  id: "SilverlightControl",
  properties: {
   width: "0px",
   height: "0px",
   version: "0.95",
   enableHtmlAccess: true
  },
  events: {}
 }); 

Now the default view of this would look like:

But lets say we added the following lines of code in our managed load event:

HtmlElement el = HtmlPage.Document.GetElementByID("fooBlock");
el.SetStyleAttribute("color", "Red");
el.SetProperty("innerText", "foo");

Now we get:

HtmlPage returns us the current page instance, if we are allowed to see it. And from there we can walk the DOM using a new set of classes under the System.Windows.Browser namespace.

Not only can you manipulate the DOM from managed, but you can call into managed from JavaScript, or fire events in both directions. This gives you a fairly tight glue to get even your standard web apps humming with managed goodness.

I dont think the potential impact of this can be understated, while I fully expect the power of .NET to be used in anger in combination with the richer user experience that you get with Silverlight, there is equal opportunity to make sure your AJAX hums even better by doing more sophisticated work client side using .NET.

If you have Beta 1 of Orcas, get started by just creating a new Silverlight project! - you can go download the extensions for Silverlight as well as the 1.1 SDK (remember to install the 1.1 Alpha of Silverlight to make sure you get the new assemblies like System.Silverlight) and check out the QuickStarts at silverlight.net

Of course, you dont want to end up just writing a desktop app inside a browser window, or do you?

 



KTC - @ 07 May 2007 11:12
Yeahm it's true. Aspects of the silverlight developer experience will be evolutionary. What's less than impressive? Components. It ships with enough XAML to be able to draw some basic objects natively. So you want a combo box? Go write it. A button? First compile the supplied custom component quickstarts, get to grips with the requirements and take it from there. As far as i can remember even good ol MX ships with a pretty handy set of UI components. Guess i have to write my own or wait for RAD to ship some candy. Orcas. So 2005 isn't extendable enough to intergrate a new project type into? Seems to handle WF, Ajax and all my Gat's ok? And the name. Come on. Flash. Silverlight. Bollocks!
KTC - @ 10 May 2007 09:00
woo hoo! [from ScottGu] Silverlight includes support for a WPF UI programming model. The Silverlight 1.1 Alpha enables you to program your UI with managed code/event handlers, and supports the ability to define and use encapsulated UI controls (built with any managed .NET language). The first Silverlight Alpha doesn't yet ship with a rich set of built-in UI controls -- we've been busy at work building the core UI infrastructure first. Don't worry, though, a rich set of high-level controls will definitely be included in the future (in the meantime you can download some nice samples of controls here). WPF for Silverlight will also ultimately ship with support for core WPF constructs like layout managers and data-binding (these features are not yet implemented in the current alpha - but are coming).
bernarda - @ 24 Oct 2007 02:43
http://georgesguetary.net/phpBB/viewtopic.php?p=7486 http://board.byethost.com/viewtopic.php?p=8592
emilywww - @ 19 Jun 2008 11:35
Hi im new to this forum. im looking for some friends and maybe an internet boyfriend :P jejeje. if anyone wants to email or message me on yahoo heres my Y!ID: [b]emilywww88[/b] oh and if you want pix just ask! IM HOT jaja!!! Heres a pic of me: http://img408.imageshack.us/img408/4498/13xa9.jpg

Add a new comment:

Name:

Website:

Comment:

history


2006 (47)
2007 (79)
2008 (55)

blogs i read


John-Daniel Trask
Andrew Peters
Ivan Towlson
Josh Robb
Chris Auld
Ivan Porto Carrero
Darryl Burling
Nigel Parker

links


Mindscape
Intergen
Microsoft Regional Director Microsoft MVP - SQL Server

RSS Feed rss feed