我有两个动画:
<Storyboard x:Key="ChangeLayout">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Canvas.Left)" Storyboard.TargetName="currentContent">
<EasingDoubleKeyFrame KeyTime="0:0:0.0" Value="900"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0">
<EasingDoubleKeyFrame.EasingFunction>
<CircleEase EasingMode="EaseInOut"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="HideLayout">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Canvas.Left)" Storyboard.TargetName="currentContent">
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="-900">
<EasingDoubleKeyFrame.EasingFunction>
<CircleEase EasingMode="EaseInOut"/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
以及开始它们的代码:
private void btnUser_Click(object sender, RoutedEventArgs e)
{
if (currentContent.Content != null)
if (currentContent.Content.GetType() == typeof(Layouts.User))
return;
((hl.Children[0] as DoubleAnimationUsingKeyFrames).KeyFrames[0] as EasingDoubleKeyFrame).Value = -this.ActualWidth;
hl.Completed += (_sender, _e) =>
{
currentContent.Content = new Layouts.User();
cl.Completed += (ssender, ee) =>
{
btnMusic.Opacity = 0.5;
btnUser.Opacity = 0.9;
};
cl.Begin();
};
hl.Begin();
}
private void btnMusic_Click(object sender, RoutedEventArgs e)
{
if (currentContent.Content != null)
if (currentContent.Content.GetType() == typeof(Layouts.Music))
return;
((hl.Children[0] as DoubleAnimationUsingKeyFrames).KeyFrames[0] as EasingDoubleKeyFrame).Value = -this.ActualWidth;
hl.Completed += (_sender, _e) =>
{
if (Layouts.Music.CurrentMusic == null)
{
Layouts.Music.CurrentMusic = new Layouts.Music();
Layouts.Music.CurrentMusic.GetMusic();
}
currentContent.Content = Layouts.Music.CurrentMusic;
cl.Completed += (ssender, ee) =>
{
btnUser.Opacity = 0.5;
btnMusic.Opacity = 0.8;
};
cl.Begin();
};
hl.Begin();
}
在用户和音乐内容之间进行几次切换后,ChangeLayout 动画开始非常缓慢和滞后,并且根据 WPF Performance Suite FPS 动画在切换后从 500 + 下降到最大 4eh 动画......找不到任何解决方案=(
对不起我的英语,我目前正在学习。