Published Monday, April 30, 2007 12:04 PM by martin

Silverlight with PHP

As you'd expect from someone who's spent the last decade working solely on the Microsoft platform, I'm a lot more au fait with ASP.NET than I am with PHP.  Nevertheless I thought it's about time I took a look at PHP, if only at the most basic level.

I wanted to create a PHP class that could serve up the XAML for a Silverlight button (of sorts).  You can see the result here.  Notice that I haven't implemented anything so fancy as clicking on this button, but mouse-enter and mouse-leave do work.

For your convenience, here's the javascript that goes with my PHP.

The PHP code itself looks like this...


<?php

 

function Button( $name, $text, $x, $y, $width, $height )

{

  echo "

  <Rectangle x:Name=\"$name\"

        Width=\"$width\"

            Height=\"$height\"

            RadiusX=\"20\"

            RadiusY=\"20\"

            Stroke=\"Black\"

            StrokeThickness=\"2\"

            Canvas.Left=\"$x\"

            Canvas.Top=\"$y\"

            Loaded=\"BLOCKED SCRIPT buttonLoaded\"

            MouseEnter=\"BLOCKED SCRIPT buttonMouseEnter\"

            MouseLeave=\"BLOCKED SCRIPT buttonMouseLeave\"

            >

    <Rectangle.Fill>

      <LinearGradientBrush StartPoint=\"0,0\" EndPoint=\"0,1\">

        <LinearGradientBrush.GradientStops>

          <GradientStop Color=\"#ffffffff\" Offset=\"0\"/>

          <GradientStop Color=\"#ff000000\" Offset=\".2\"/>

          <GradientStop Color=\"#ff900030\" Offset=\".8\" x:Name=\"", $name, "BaseColourStop\" />

        </LinearGradientBrush.GradientStops>

      </LinearGradientBrush>

    </Rectangle.Fill>

  </Rectangle>

 

  <TextBlock x:Name=\"", $name, "Text\" Foreground=\"White\" FontSize=\"24pt\">

    $text

  </TextBlock>

  ";

}

 

function EmitHeader()

{

  echo '<Canvas Opacity="1"

        xmlns="http://schemas.microsoft.com/client/2007"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

  x:Name="parentCanvas" Loaded="BLOCKED SCRIPTrootLoaded">';

}

 

function EmitFooter()

{

  echo '</Canvas>

  ';

}

 

 

EmitHeader();

Button('button1', 'Click Me', 10, 10, 200, 70);

Button('button2', 'Me Too', 10, 100, 200, 70);

EmitFooter();

 

?>

I know it could be tidier, but you get the idea :-)

 

Technorati tags: , ,