2011-03-28 12 views
0

我需要知道如何使用同樣的動畫dynamicaly更改目標名稱「WPF」創建從混合(XAML)和改變目標名稱情節串連圖板從C#

請看下面是我的XAML和C#代碼

WPF的代碼

XAML代碼

<Storyboard x:Key="deepanshu"> 
    <DoubleAnimationUsingKeyFrames x:Name="gupta" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="image1"> 
     <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.641"/> 
     <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/> 
    </DoubleAnimationUsingKeyFrames> 
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="image1">  
     <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.689"/> 
     <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/> 
    </DoubleAnimationUsingKeyFrames> 
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="image1"> 
     <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="-1"/> 
     <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/> 
    </DoubleAnimationUsingKeyFrames> 
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="image1"> 
     <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.5"/> 
     <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/> 
    </DoubleAnimationUsingKeyFrames> 
</Storyboard> 

C#代碼

Storyboard sb = (Storyboard)FindResource("deepanshu"); 
// now how to change storyboard target name from image1 to image2 

回答

-1

這對你很有幫助。

Storyboard sb = (Storyboard)FindResource("deepanshu"); 
Storyboard.SetTargetName(sb.Children[0],"image2"); 
Storyboard.SetTargetName(sb.Children[1],"image2"); 
Storyboard.SetTargetName(sb.Children[2],"image2"); 
sb.Begin();