C# 为什么我的WPF动画只开始一次?
我有一个动画,它在第一次被触发时工作正常,但是当C# 为什么我的WPF动画只开始一次?,c#,wpf,animation,C#,Wpf,Animation,我有一个动画,它在第一次被触发时工作正常,但是当GoNextCmd第二次被提升为true时,动画就不再启动了。这是我的密码: <ItemsControl DockPanel.Dock="Top" ItemsSource="{Binding ViewCollection}" x:Name="itemsControl"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate>
GoNextCmd
第二次被提升为true时,动画就不再启动了。这是我的密码:
<ItemsControl DockPanel.Dock="Top" ItemsSource="{Binding ViewCollection}" x:Name="itemsControl">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentControl Content="{Binding}" Width="500" Name="toMove">
</ContentControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.Style>
<Style TargetType="ItemsControl">
<Style.Triggers>
<DataTrigger Binding="{Binding GoNextCmd}" Value="true">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<ThicknessAnimation RepeatBehavior="1x" FillBehavior="Stop" Storyboard.TargetProperty="Margin" By="-250,0,0,0" Duration="0:0:1">
<ThicknessAnimation.EasingFunction>
<QuinticEase EasingMode="EaseInOut" />
</ThicknessAnimation.EasingFunction>
</ThicknessAnimation>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</ItemsControl.Style>
</ItemsControl>
有人知道吗?我不知道你说的上升为true的命令是什么意思,但是对于DataTriggers,你应该使用INotifyPropertyChanged(当使用setter时上升为PropertyChanged)来使用属性 是的,这是我已经做过的。第一次将属性设置为true时,它工作正常。但是如果我再设置一次,动画就不会启动。你在一个干净的项目中尝试过吗?它对我来说效果很好,每次属性值设置为True时都会触发动画。我尝试了它,但仍然不起作用。你测试它的代码是什么?我用简单视图模型测试了你的控件,该模型实现了
INotifyPropertyChanged
,它有一些简单的ViewCollection
列表和bool GoNextCmd
propertyHum,看起来与我的代码相同。。。有没有一种方法可以向我展示您的视图模型代码和xaml?实际上没有多少代码可以展示。一个observedcollection
列表属性和一个bool
属性。单击按钮时,我会更改它,并且INotifyPropertyChanged
implementation+您的XAML。