2009年2月27日

Silverlight Storyboard Animation

有時候我必須透過程式直接產生物件,並加入動畫的效果,例如由網路讀取使用者的相簿數量,然後在相簿出現的時後,產生移動或淡出的特效。下面的程式碼可以幫助學會 Storyboard 的使用,其中,特別要注意的就是 PropertyPath 的建立。
 
for (int i = 0; i < inData.Albums.Count; i++ )
{
IAlbumData albumData = inData.Albums[i];
Album newAlbum = new Album();
m_AlbumList.Add(newAlbum);

Canvas.SetLeft(newAlbum, 20 + 30 * i);

this.LayoutRoot.Children.Add(newAlbum);
newAlbum.Click += new RoutedEventHandler(newAlbum_Click);

TranslateTransform translate = new TranslateTransform();
newAlbum.RenderTransform = translate;

Storyboard sb = new Storyboard();

DoubleAnimation moveAnimation = new DoubleAnimation();
moveAnimation.From = 0;
moveAnimation.To = 20 + 50 * i;
Duration dur = TimeSpan.FromSeconds(0.5);
moveAnimation.Duration = dur;
Storyboard.SetTarget(moveAnimation, translate);
Storyboard.SetTargetProperty(moveAnimation, new PropertyPath(TranslateTransform.XProperty));
sb.Children.Add(moveAnimation);
sb.Begin();
}

沒有留言:

Deploying Vue & .NET with Google OAuth on GCP Cloud Run

Deploying Vue & .NET with Google OAuth on GCP Cloud Run Deploying Vue & .NET with Google OAuth on GCP Cloud Run...