1
我在停止動畫時遇到了一些問題,它會一直持續下去。我會認爲RepeatBehavior應該控制這一點,但它似乎不起作用。WPF使用RepeatBehavior停止ColorAnimation
<Grid.Style>
<Style TargetType="Grid">
<Style.Triggers>
<DataTrigger Binding="{Binding IsNew}" Value="true">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation RepeatBehavior="1"
Storyboard.TargetProperty="Background.(SolidColorBrush.Color)"
To="LightGreen" Duration="0:0:0.25" AutoReverse="True" >
</ColorAnimation>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
<DataTrigger Binding="{Binding IsNew}" Value="false">
<Setter Property="Background" Value="WhiteSmoke"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
原因很簡單:'RepeatBehavior = 「1」'指定*一個天*,而'RepeatBehavior =「1倍「'指定*一次*。您可能需要查看[MSDN上的RepeatBehavior文檔](http://msdn.microsoft.com/library/system.windows.media.animation.timeline.repeatbehavior.aspx)。 – Clemens
@克萊門斯感謝您的意見。我更新了我的答案幷包含了MSDN代碼。 – Tejo