"WPF" creating storyboard from blend (xaml) and change target name from c#
i need to know how to change target name dynamicaly with same animation
Please find Below is my code of WPF for xaml and c# code
xaml code
<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>
开发者_如何学Go <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# code
Storyboard sb = (Storyboard)FindResource("deepanshu");
// now how to change storyboard target name from image1 to image2
Something like SetTarget
: http://msdn.microsoft.com/en-us/library/cc663141.aspx:
Storyboard.SetTargetName(sb.Children[0],"image2");
This will help you well.
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();
精彩评论