每当StatusBarItem的文本被更新时,我都想将其动画化,VisualState很好,如果我在MouseEnter事件中触发它,那么它就会播放;但是,在DataContextChanged事件期间,我无法让它播放。
<Window.Resources>
<Color x:Key="ColorRed">Red</Color>
</Window.Resources>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="VisualStateGroup">
<VisualState x:Name="Animate">
<Storyboard AutoReverse="True">
<ColorAnimationUsingKeyFrames Storyboard.TargetName="StatusBarItem1" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
<EasingColorKeyFrame KeyTime="0:0:0.2" Value="{StaticResource ColorRed}" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<StatusBarItem x:Name="StatusBarItem1" Content="{Binding TargetNullValue='Placeholder'}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="DataContextChanged">
<ei:GoToStateAction StateName="Animate" />
</i:EventTrigger>
</i:Interaction.Triggers>
</StatusBarItem>我是这样更新DataContext的:
...
catch (Exception ex)
{
var s = string.Format("Building preview for asset failed: {0}", ex.Message);
StatusBarItem1.DataContext = s;
}如果我听这个活动,它确实被称为:
StatusBarItem1.DataContextChanged += StatusBarItem1_DataContextChanged;
void StatusBarItem1_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
}当StatusBarItem文本发生变化时,我如何触发动画?
发布于 2014-01-03 15:45:58
请参阅this solution,这表明这需要在代码隐藏上完成,而不能在纯XAML中完成。问题并不完全相同,但通过手动启动动画,同样的解决方案应该适用于您。
https://stackoverflow.com/questions/20907260
复制相似问题