我想在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
文字发生变化,我该如何触发动画?