在Silverlight 1.1 Alpha版本里面不能通过直接New一个Storyboard对象来使用,只能采用以下方法代替解决,希望2.0里面能够解决这个问题,标记一下
<Canvas
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="parentCanvas"
Loaded="Page_Loaded"
x:Class="SilverlightTests.Page;assembly=ClientBin/SilverlightTests.dll"
Width="640"
Height="480"
Background="White">
<Rectangle x:Name="rectangle" Width="100" Height="200" Fill="#FFC13131" />
</Canvas>
public void Page_Loaded(object o, EventArgs e)
{
// Required to initialize variables
InitializeComponent();
string xaml = "<Storyboard><ColorAnimationUsingKeyFrames BeginTime=/"00:00:00/" " +
"Storyboard.TargetName=/"rectangle/" Storyboard.TargetProperty=/"(Shape.Fill)." +
"(SolidColorBrush.Color)/"><SplineColorKeyFrame KeyTime=/"00:00:00/" "+
"Value=/"#FF2C0606/"/><SplineColorKeyFrame KeyTime=/"00:00:01/" "+
"Value=/"#FFDD4848/"/></ColorAnimationUsingKeyFrames></Storyboard>"
Storyboard anim = (Storyboard)XamlReader.Load(xaml);
this.Resources.Add(anim);
anim.Begin();//run the animation
}