如何在WPF中暂停和恢复布局? [英] How can I suspend and resume layout in WPF?

查看:56
本文介绍了如何在WPF中暂停和恢复布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在WPF中暂停和恢复布局?听说没有必要.但这是极其必要的!

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 rendered one by one, it creates a delay effect.

以下是一些代码:



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.
   ...
}

推荐答案

WPF是保留的合成引擎.这意味着您不必钩住 Rendering 事件就可以自己进行渲染,而可以使用要放入树中的节点来组成图像.有关WPF架构的详细信息,请参见此处: WPF架构.我可以向您保证,如果您对本文档以及Rick Sladkey发送的布局系统链接完全了解,还应该理解为什么要继续使用WPF,为什么应该更改代码.

WPF is a retained composition engine. What it means is you don't have to do the rendering yourself hooking the Rendering event, but rather compose an image using nodes that you will put in a tree. See here for details on WPF architecture: WPF Architecture. I can assure you if you understand perfectly this document as well as the Layout System link Rick Sladkey sent, you should also understand why you should change your code if you want to continue with WPF.

如果您使用WPF正确播放(例如:使用依赖项属性,例如覆盖Measure& Arrange方法),您将看到它是一个非常强大的引擎,能够在图形树中显示数千个节点.我建议另一种有用的阅读方法: ZoomableApplication2:一百万个项目

If you play it right with WPF (ie: use dependency properties, override Measure & Arrange methods for example), you will see it's a very powerful engine capable of displaying thousands of nodes in the graphical tree. I suggest another useful reading: ZoomableApplication2: A Million Items

这篇关于如何在WPF中暂停和恢复布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆