如何为动画指定目标?

时间:2016-04-13 07:35:04

标签: c# wpf xaml wpf-animation

在您阅读此问题之前,请see this

现在我在用户控件资源中定义了故事板,并在ViewModel中定义的事件中触发它:

<UserControl.Resources>
    <Storyboard x:Key="Storyboard2">
        <DoubleAnimation Storyboard.TargetName="Btn_Import" Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:2"/>
        <DoubleAnimation Storyboard.TargetName="Studio" Storyboard.TargetProperty="Opacity" From="0" To="{Binding StudioOpacityValue}" Duration="0:0:2"/>

        <DoubleAnimation Storyboard.TargetName="StudioTranslateLeftToRight" Storyboard.TargetProperty="X" By="{Binding StudioStartingPointWidth}"  Duration="0:0:2">
            <DoubleAnimation.EasingFunction>
                <CubicEase EasingMode="EaseInOut"/>
            </DoubleAnimation.EasingFunction>
        </DoubleAnimation>

        <DoubleAnimation Storyboard.TargetName="Animation" Storyboard.TargetProperty="Opacity" From="0" To="{Binding AnimationOpacityValue}" Duration="0:0:2"/>
        <DoubleAnimation Storyboard.TargetName="Record" Storyboard.TargetProperty="Opacity" From="0" To="{Binding RecordOpacityValue}" Duration="0:0:2"/>
        <DoubleAnimation Storyboard.TargetName="Info" Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:2"/>
        <DoubleAnimation Storyboard.TargetName="textframe_image" Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:2"/>
        <local:CommandFakeAnimation Command="{Binding Path=MainButtonClickedCommand, Mode=OneWay}" CommandParameter="Hide" Storyboard.TargetProperty="Opacity" Duration="0:0:0"/>
    </Storyboard>
</UserControl.Resources>

然后我有一个动画故事板的事件:

<i:Interaction.Triggers>
     <i:EventTrigger EventName="FadeInMainButtonsAfterStudio" SourceObject="{Binding Mode=OneWay}">
        <ei:ControlStoryboardAction Storyboard="{StaticResource Storyboard2}"/>
    </i:EventTrigger>
</i:Interaction.Triggers>

我要将动画应用到的控件是:

<Button x:Name ="Studio" Grid.Row="33" Grid.Column="57" Grid.ColumnSpan="36" Grid.RowSpan="36"  IsEnabled="{Binding IsStudioEnabled}" Opacity="{Binding StudioOpacityValue}" Command="{Binding MainButtonClickedCommand}" CommandParameter="Show">
    <Button.Template>
        <ControlTemplate>
            <Grid RenderTransformOrigin="0.5,0.5" x:Name="bg">
                <Image x:Name ="studio_image" Source="{Binding StudioBtnBaseImagePath}"/>
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter TargetName="studio_image" Property="Source" Value="{Binding StudioBtnOverImagePath}" />
                    </Trigger>

                <Trigger Property="ButtonBase.IsPressed"  Value ="True">
                    <Setter TargetName="bg" Property="RenderTransform">
                        <Setter.Value>
                            <ScaleTransform ScaleX="0.9" ScaleY="0.9"/>
                        </Setter.Value>
                    </Setter>
                </Trigger>

            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Button.Template>

    <Button.RenderTransform>
        <TransformGroup>
            <TranslateTransform x:Name="StudioTranslateLeftToRight" X="0"/>
        </TransformGroup>
    </Button.RenderTransform>

</Button>

但是我收到以下运行时错误:

  

其他信息:未指定目标   &#39; MainMenu.DummyAnimations.CommandFakeAnimation&#39;

这可能是什么问题?

1 个答案:

答案 0 :(得分:1)

正如您所收到的错误中所述,您尚未为自定义动画提供Storyboard.TargetName local:CommandFakeAnimation