开发者

Redrawing to a silverlight canvas every cycle of a loop. Is it possible?

any help or pointers would be massively appreciated.

Basically i'm trying to EITHER move OR redraw some ellipses to a canvas once a "turn".

At the moment I can click a button to RenderTransform the ellipse to a new location within the canvas. Whenever I try to do this more than once, for example, incrementing the TranslateTransform X and Y values by one each loop, the whole application hangs. Is this an issues which RenderTransform? The Canvas? The MainPage thread? The code looks solid, so its a mystery as to why it simply wouldnt move the ellipse more than once.

private void update()
    {
        int x = 0;
        int y = 0;
        while (turns <= 5)
        {
            TranslateTransform t = new TranslateTransform();
            t.X 开发者_开发百科= x + 1;
            t.Y = y + 1;
            // agent is a child element of a canvas.
            agent.RenderTransform = t;
            turns--;
        }
    }


You can use CompositionTarget it will help you
look at this example
another good example

use it like this:

private void Update(object sender, EventArgs e)
{
     //Your code here
}

and hook the Rendering event CompositionTarget.Rendering += Update;

Edit: If you are using Canvas it's better to use Canvas.Left and Canvas.Top attached properties

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜