“WPF”从 Blend (xaml) 创建故事板并从 C# 更改目标名称

发布于 2024-10-26 21:43:12 字数 1797 浏览 1 评论 0原文

我需要知道如何使用相同的动画动态更改目标名称

请查找下面是我的用于 xaml 的 WPF 代码和 c# 代码

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

早乙女 2024-11-02 21:43:12

类似于 SetTargethttp://msdn.microsoft。 com/en-us/library/cc663141.aspx

Storyboard.SetTargetName(sb.Children[0],"image2");

Something like SetTarget: http://msdn.microsoft.com/en-us/library/cc663141.aspx:

Storyboard.SetTargetName(sb.Children[0],"image2");
御守 2024-11-02 21:43:12

这会对你有很大帮助。

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();

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文