動態生成Storyboard

在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
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章