开发者

DrawingVisuals host and layout performance

I have a WPF (.NET 3.5) control which renders about 20000 rectangles. This MyControl is derived from Canvas. I'm putting a MyVisualsHost as a child into MyControl like this:

public class MyControl : Canvas
{
    private readonly MyVisualsHost host = new MyVisualsHost();
    private List<MyVisual> items = Enumerable.Range(0, 20000).Select(...).ToList();
    public MyControl()
    {
       this.Children.Add(host);
    }
}

So, I'm putting it into Grid or into Window.Content and it renders items quite fast(1 second). When I resize window, Rectangles are rearranged and redrawn(also in 1 second).

But when I'm putting ComboBox into the XAML along with MyControl:

<Grid>
   <ComboBox/>
   <MyControl />
</Grid>
开发者_运维问答

Rendering on rearrange slows down to 5-10 seconds.

Anyone has any idea about that? Thanks in advance.

P.S. you can download the demo project Here


Okay. I've managed it. Each visual was opening/closing it's own DrawingContext and it was taking far too much time. When I changed the code of visual's rendering to use VisualHost's DrawingContext instance which was passed as an argument to OnRender method, It took 1-2 seconds to render 20000 viuals again. So everything is well now, even though I lost hit testing capability because of using such rendering algorithm.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜