我在Expression Blend 4中创建了一个WPF Storyboard动画,它可以使图像逐渐模糊。当鼠标离开图像时,有没有办法让Storyboard被撤销或反向播放?我可以使用Storyboard.Remove()来触发,但那样并不能实现倒放。
在Expression Blend 4中有没有办法实现这个效果?
我在Expression Blend 4中创建了一个WPF Storyboard动画,它可以使图像逐渐模糊。当鼠标离开图像时,有没有办法让Storyboard被撤销或反向播放?我可以使用Storyboard.Remove()来触发,但那样并不能实现倒放。
在Expression Blend 4中有没有办法实现这个效果?
由于您正在使用Blend,因此您应该利用Blend对VisualStateManager
的支持。您所要做的就是描述对象在各种状态下的外观,例如MouseOver
和Normal
以及各种状态之间的转换需要多长时间,然后视觉状态管理器会计算出如何在状态之间进行过渡。
图像没有任何视觉状态,但您可以编辑Button
模板并使其内容为图像,然后编辑按钮的状态。我已经这样做了,并清理了XAML以演示该技术:
<Grid>
<Grid.Resources>
<Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Image x:Name="image" Height="100" Width="Auto" Source="http://thecybershadow.net/misc/stackoverflow.png" Margin="0,0,-25,0">
<Image.Effect>
<DropShadowEffect ShadowDepth="0"/>
</Image.Effect>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:0.5"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Effect).(DropShadowEffect.ShadowDepth)" Storyboard.TargetName="image">
<EasingDoubleKeyFrame KeyTime="0" Value="15"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed"/>
<VisualState x:Name="Disabled"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Image>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<Button Style="{StaticResource ButtonStyle1}"/>
</Grid>
请注意,Blend可以为您完成所有这些操作,但了解XAML将有所帮助。以下是一个针对Blend的教程: