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.
...
}
without calling
UpdateLayout
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
简而言之,他有一个过程,添加 /或操纵元素(我认为是循环),他希望在循环中冻结渲染过程,因为我假设1。 taking place and 2. It's slow