How can I suspend and resume layout in WPF?

问题描述 投票:0回答:4

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

我处理许多变更位置,如果将它们一个一个一个一个一个一个呈现,它会产生延迟效果。

这里是一些代码:

CompositionTarget.Rendering += new EventHandler(Draw); void Draw(object sender, EventArgs e) { //Clean screen for (int i = mainCanvas.Children.Count - 1; i > -1; i--) { if (mainCanvas.Children[i] is PlayerUserControl || mainCanvas.Children[i] is Image) { mainCanvas.Children.Remove(mainCanvas.Children[i]); } } //DRAW FLOOR AROUND FloorService.FloorEntity[] floorsAround = floorService.selectFloorsAround(Player.id); for... { Image image = new Image(); image.Source = new BitmapImage(new Uri("/" + floorsAround[i].ImageSource, UriKind.Relative)); mainCanvas.Children.Add(image); } //DRAW PLAYERS AROUND //Its similar as draw floors around. ... }
    
.net wpf
4个回答
13
投票
WPF是

重构成引擎。这意味着您不必做渲染的效果,而是使用将放入树上放入的节点的图像来进行Rendering事件。有关WPF架构的详细信息,请参见此处:

WPFArchitecture
。我可以向您保证,如果您完美理解本文档以及Rick Sladkey发送的布局系统链接,您还应该理解为什么要继续使用WPF。 如果您使用wpf直接播放(即:使用依赖项属性,覆盖措施和安排方法),您将看到它是一个非常强大的引擎,能够在图形树中显示数千个节点。 您没有提供足够的信息,除了说您的“处理很多更改”。 但是,如果您进行所有这些更改:

序列

7
投票
从UI线程

without calling
    UpdateLayout
  • , and
  • without returning
  • then no layout occurs in-bewteen those changes.  因此,没有什么可以暂停或恢复的,因为布局总是会推迟到您进行此类更改之后。
    
    
    因此,如果您遇到延误,那不是因为您没有批处理您的布局更改Ala Winforms。 结果,减少延迟的唯一方法,如果确实是由于布局造成的,则是避免不必要的布局重新计算。 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

  • 您已经考虑过先从窗户上卸下画布,然后将其隐藏起来,然后清除并将所有物品重新添加到画布中,然后将画布重新添加回窗口?
  • He clearly posted enough info that even I with limited wpf experience knew exactly what he was talking about.
简而言之,他有一个过程,添加 /或操纵元素(我认为是循环),他希望在循环中冻结渲染过程,因为我假设1。 taking place and 2. It's slow

0
投票
There was a post above that mentioned removing the canvas first... well that’s almost it. 只需设置主要父母倒塌的可见性,执行元素添加/操纵,然后使父级可见


0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.