Silverlight powered by PHP

Posted on 1:32pm 12/09/2007 by Bruno Silva in Programming, Silverlight

Silverlight powered by PHP

I’ve written this demo for a presentation two weeks ago, but I didn’t have a change to show it. I’ll show you how to dynamically generate a Silverlight application. Well, it is just a still image, but this way it is simple enough to show you the main idea.

Here is the look of the application. Each time you load the page it generates some random squares with random colors and positions.

From a common Silverlight application, here is the list of changes you have to do to get it working.

1. Create XAML generator (Page.xaml.php)

Create an PHP file which outputs XAML code. Take a look at this one. It has a function that generates a random RGB color with an Alpha value. It has also a function that generates a rectangle in XAML code based on some parameters. Using these functions the PHP script creates 150 squares with random position, size and color.

2. Change the XAML file reference (CreateSilverlight.js)

In the javascript file where the Silverlight Control is created you have to change the XAML reference to Page.xaml.php.It this CreateSilverlight.js file you can see how it looks.

3. Have some fun (Page.xaml.js)

I added some behavior to this application. When you click somewhere it changes between full-screen and window mode.

Conclusions

This is a simple example, but imagine what you can do. Things like connect to a database and generate some content, create parametrized animations, and so on. Just give it a try. You can download the whole demo here.

2 Responses to “Silverlight powered by PHP”

  1. Hola, excelente codigo. Tengo sitio e-commerce en PHP. Es posible utilizar Silverlight para llenar un control-lista con un XML ejecutado mediante AJAX?

    Hi, cool code, I have an e-commerce website made built in PHP. It’s possible to develop with Ms Silverlight and populate a List-Control with XML (generated by PHP, example: product title and price) called with an AJAX function?

    thanl’s

  2. Hi!
    Yes you can. You can use DOM to access the XAML tree as you already do in HTML and manipulate elements (by adding new ones, deleting others and editing the existing ones).

    Since behavior in Silverlight is coded in Javascript, you can assign a handler to a onClick event on a button (as an example)and execute some asynchronous call to the server.
    Although I haven’t tried it :D

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© Bruno Silva | Powered by Wordpress