如何使用图像预加载控件?

时间:2020-12-31 20:19:38

I am working on a WPF application where I need smooth animations and transitions between pages.

我正在开发一个WPF应用程序,我需要平滑的动画和页面之间的过渡。

On startup, I instantiate all my controls, with Visibility : Collapsed, and when I go from a control to another, I animate the two controls and change the visibility.

在启动时,我使用Visibility:Collapsed实例化我的所有控件,当我从控件转到另一个控件时,我为两个控件设置动画并更改可见性。

My problem is on a control with several images : the first time I display it, we don't see the animation (probably because it loads the images in the same time). When I load it a second time, there's no problem.

我的问题在于有几个图像的控件:第一次显示它时,我们看不到动画(可能是因为它同时加载了图像)。当我第二次加载它时,没有问题。

Is there a way to preload this control in order to always have smooth animations ?

有没有办法预加载此控件,以便始终拥有流畅的动画?

1 个解决方案

#1


0  

In the codebehind you can have an event handler OnLoaded() for when the your control is loaded for the first time. Here you can load in the images or even have them start as Visible so they are loaded and at the end of the handler, have them go back to being Collapsed.

在代码隐藏中,您可以在第一次加载控件时使用事件处理程序OnLoaded()。在这里,您可以加载图像,甚至可以将它们作为Visible开始,这样它们就会被加载,并且在处理程序的最后,让它们回到Collapsed。

#1


0  

In the codebehind you can have an event handler OnLoaded() for when the your control is loaded for the first time. Here you can load in the images or even have them start as Visible so they are loaded and at the end of the handler, have them go back to being Collapsed.

在代码隐藏中,您可以在第一次加载控件时使用事件处理程序OnLoaded()。在这里,您可以加载图像,甚至可以将它们作为Visible开始,这样它们就会被加载,并且在处理程序的最后,让它们回到Collapsed。