How can I suspend and resume layout in WPF?

后端 未结 3 2026
灰色年华
灰色年华 2021-02-08 15:06

How can I suspend and resume layout in WPF? I heard that this is not necessary. But this is extremely necessary!

I process a lot of change positions, and if they are ren

3条回答
  •  梦谈多话
    2021-02-08 15:44

    You haven't given enough information except to say that your "process a lot of changes". But if you make all those changes:

    • sequentially
    • from the UI thread
    • without calling UpdateLayout, and
    • without returning

    then no layout occurs in-bewteen those changes. Therefore there is nothing to suspend or resume because layout is always deferred until after you return from making these kinds of changes.

    So, if you are experiencing delays, then is is not because your are not batching your layout changes ala WinForms. As a result, the only way to reduce the delay, if it is indeed due to layout, is to avoid unnecessary layout recalculations. Again, without knowing what you are doing, it is impossible to suggest anything concrete. But there are many properties you can avoid to might trigger a recursive layout pass. See Layout Performance Considerations in this article:

    • Layout System

提交回复
热议问题