WPF应用程序中的第一个控件显示冻结UI

时间:2022-07-06 19:30:48

Edit
I changed the title because I found the real cause of the freeze. The cause is in my awnser

编辑我更改了标题,因为我找到了冻结的真正原因。原因在于我的灵感

In WPF, the first time you display a control, it can be slow because the XAML will be parsed. Next time the control is displayed, it will be instantanous because the XAML is already parsed.

在WPF中,第一次显示控件时,它可能会很慢,因为将解析XAML。下次显示控件时,它将是瞬时的,因为已经解析了XAML。

I tried to reduce the UI freeze by using a defered visual loading system which make visual collapsed and make them visible in a low priority dispatcher call. This work very will with ItemsControl with a lot of items but it still doesn't solve the first parsing UI freeze.

我试图通过使用延迟的可视加载系统来减少UI冻结,这使得视觉崩溃并使它们在低优先级调度程序调用中可见。这项工作将与ItemsControl一起使用很多项目,但它仍然无法解决第一次解析UI冻结。

Is there a good way to reduce the freeze caused by XAML parsing?

有没有一种很好的方法来减少XAML解析引起的冻结?

I was thinking about parsing all the XAML at app startup. It would slowdown the startup but the application will be without freeze after this. The difficulty is how to get all the BALM files (compiled XAML) and how to store the result in the same place where WPF look for them.

我正在考虑在应用启动时解析所有XAML。它会减慢启动速度,但应用程序将在此之后不会冻结。困难在于如何获取所有BALM文件(已编译的XAML)以及如何将结果存储在WPF查找它们的相同位置。

1 个解决方案

#1


0  

I was wrong. the slow down did not came from XAML parsing. it came from some static contructor who was loading some dll. Thats why it was slow only the first time. I moved the static initialisation to a thread.

我错了。缓慢不是来自XAML解析。它来自一些正在加载一些dll的静态构造函数。这就是为什么它只是第一次变慢。我将静态初始化移动到一个线程。

#1


0  

I was wrong. the slow down did not came from XAML parsing. it came from some static contructor who was loading some dll. Thats why it was slow only the first time. I moved the static initialisation to a thread.

我错了。缓慢不是来自XAML解析。它来自一些正在加载一些dll的静态构造函数。这就是为什么它只是第一次变慢。我将静态初始化移动到一个线程。