问题
Before you read this question, please see this
Now I have the storyboard defined in the user control resources and it gets triggered it on an event that is defined in 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>
and then I have an event that trigers the storyboard:
<i:Interaction.Triggers>
<i:EventTrigger EventName="FadeInMainButtonsAfterStudio" SourceObject="{Binding Mode=OneWay}">
<ei:ControlStoryboardAction Storyboard="{StaticResource Storyboard2}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
and the control that I want to apply the animation to is:
<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>
but I get the following runtime error:
Additional information: No target was specified for 'MainMenu.DummyAnimations.CommandFakeAnimation'
What could be the problem with this?
回答1:
As clearly described in the error you are getting, you have not provided Storyboard.TargetName
for your custom Animation local:CommandFakeAnimation
来源:https://stackoverflow.com/questions/36591570/how-to-specify-a-target-for-animation