我正在尝试构建一个简单的网格,以显示需要显示箭头以指示值增加或减少的价格。
此处,Visibility属性可以正常显示/隐藏向上或向下箭头。但是,如果Ask在后续更改中向一个方向移动,则动画不会触发。我应该尝试创建另一个属性来触发动画吗?我可以在代码中执行此操作,但如果可能,我希望在XAML中执行此操作。
下面给出的模板列定义
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Width="40" Text ="{Binding Path=Ask}"></TextBlock>
<TextBlock x:Name="Up">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding AskUp}" Value="True">
<Setter Property="Visibility" Value="Visible"/>
<DataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource blinkAnimation}" Name="upAnimation"/>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
<Path x:Name="UpArrow" Data="M 0 8 L 4 0 L 8 8 Z" Fill="Green"/>
</TextBlock>
<TextBlock x:Name="Down">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding AskUp}" Value="False">
<Setter Property="Visibility" Value="Visible"/>
<DataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource blinkAnimation}" Name="downAnimation"/>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
<Path x:Name="DownArrow" Data="M 0 0 L 4 8 L 8 0 Z" Fill="Red" />
</TextBlock>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
我的动画片段是
<Window.Resources>
<Storyboard x:Key="blinkAnimation">
<DoubleAnimation Storyboard.TargetProperty ="(UIElement.Opacity)" From="1" To="0" Duration="0:0:0.125" AutoReverse="True" FillBehavior="Stop" RepeatBehavior="0:0:1">
</DoubleAnimation>
</Storyboard>
</Window.Resources>