C# WPF双重动画使用关键帧跳过帧
我正在尝试使用DoubleAnimationUsingKeyFrames和DiscretedDoubleKeyframe为每个关键帧设置滑块动画。但是,在播放情节提要时似乎会跳过帧,也就是说,ValueChanged事件不会针对每个关键帧触发。故事板和动画在代码隐藏中设置如下:C# WPF双重动画使用关键帧跳过帧,c#,wpf,animation,C#,Wpf,Animation,我正在尝试使用DoubleAnimationUsingKeyFrames和DiscretedDoubleKeyframe为每个关键帧设置滑块动画。但是,在播放情节提要时似乎会跳过帧,也就是说,ValueChanged事件不会针对每个关键帧触发。故事板和动画在代码隐藏中设置如下: DoubleAnimationUsingKeyFrames _timelineAnimation = new DoubleAnimationUsingKeyFrames(); Storyboard _timelineSt
DoubleAnimationUsingKeyFrames _timelineAnimation = new DoubleAnimationUsingKeyFrames();
Storyboard _timelineStoryboard = new Storyboard();
void SetupTimeline()
{
// set up timeline storyboard animation
_timelineAnimation.SpeedRatio = 1.0;
Storyboard.SetTarget(_timelineAnimation, timelineSlider);
Storyboard.SetTargetProperty(_timelineAnimation, new PropertyPath(Slider.ValueProperty));
_timelineStoryboard.Children.Add(_timelineAnimation);
timelineSlider.ValueChanged += TimelineSlider_ValueChanged;
}
void StartTimeline(List<double> times)
{
foreach (double time in times)
{
double value = time - timelineSlider.Value;
var keyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(value));
_timelineAnimation.KeyFrames.Add(new DiscreteDoubleKeyFrame(time, keyTime));
}
_timelineStoryboard.Begin(timelineSlider, true);
}
// this does not fire for every key frame
void TimelineSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
Debug.Print($"TimelineSlider_ValueChanged {e.NewValue}");
}
我想问题可能是数据项靠得太近。有没有办法加快动画计时器的分辨率?或者关于解决方案的任何其他建议?事实上,当两个帧之间的间隔设置为30毫秒左右时,可能会跳过某些帧 这很像WPF调度员。WPF Dispatchermer,不管它有多小,大约每30毫秒只会滴答一次 为了产生动画效果,WPF使用一个信号来定期更新。当它勾选时,将重新计算滑块的动画属性(本例中为“值”属性),并更新UI。很明显,它选择了时间线中的“最新”帧,并丢弃了那些已经过时的帧 时间管理器每秒滴答多次;根据可用系统资源的不同,每秒发生的实际滴答数也会有所不同
即使你设法加快分辨率计时器的速度——我想用户界面计时器是不可能的,比如说,让它每1毫秒跳一次,人眼也无法感知动画中如此高的频率,而且,显示器的显示频率只有50-60赫兹 谢谢你的回答。关于我所期望的情况。我试图用动画处理一系列变化的事件,这些事件通过一个滑块驱动仪表板显示,该滑块充当时间轴。重要的是不要丢弃任何事件。我将不得不使用类似于反应式的东西来驱动时间线。
136.224
136.238
136.244
136.2441
136.246
136.2461
136.264
136.274
136.294
136.2941
136.296
136.2961