【问题标题】:"WPF" creating storyboard from blend (xaml) and change target name from c#“WPF”从混合(xaml)创建故事板并从 c# 更改目标名称
【发布时间】:2011-07-24 08:02:12
【问题描述】:

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

请在下面找到我的 WPF 代码,用于 xaml 和 c# 代码

xml 代码

<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

【问题讨论】:

    标签: c# wpf xaml expression-blend storyboard


    【解决方案1】:

    类似SetTarget:http://msdn.microsoft.com/en-us/library/cc663141.aspx:

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

    【讨论】:

      【解决方案2】:

      这对你很有帮助。

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

      【讨论】:

        猜你喜欢
        • 2021-02-16
        • 2015-03-16
        • 1970-01-01
        • 2015-10-05
        • 2013-10-02
        • 2017-02-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多