Friday, February 6, 2009

Simple Colour Animation in Silverlight 2.0 using inline XAML

If you do not want your Silverlight pluggin to look for the xap file in its relative path ..go for the inline XAML concept. Its pretty simple and easy

A sample code which do the colour animation is as follows

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>BugRepro</title>
<SCRIPT type="text/xaml" id="xaml1">
   1:  
   2:     <Canvas
   3:     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   4:     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
   5:     <Canvas.Triggers>
   6:       <EventTrigger  RoutedEvent="Canvas.Loaded" >
   7:       <BeginStoryboard >
   8:     <Storyboard x:Name="myAnimation" RepeatBehavior='Forever'>
   9:     <ColorAnimation    
  10:               Storyboard.TargetName="myRectangle"     
  11:               Storyboard.TargetProperty='(Shape.Fill).(SolidColorBrush.Color)'    
  12:               From="Red"    
  13:               To="Green"                  
  14:               Duration="0:0:0.5"    
  15:               AutoReverse="True"/>  
  16:     </Storyboard>
  17:       </BeginStoryboard>
  18:       </EventTrigger>
  19:     </Canvas.Triggers>
  20:     <Canvas Background="White" Width="100" Height="100">
  21:     <Rectangle x:Name="myRectangle" Fill='Red' Height='100' Width='100'/>
  22:     </Canvas>
  23:     </Canvas>
  24:     
</SCRIPT>
</head>
<body>
<div>
<object data=data:application/x-silverlight, type=application/x-silverlight-2
width="100" height="100" id="Ag1">
<param name="Source" value="#xaml1" />
</object></div>
</body>
</html>

No comments:

Post a Comment