Animate a DrawingVisual

I'm need to animate a bunch of DrawingVisual objects that I hold in a VisualCollection but something like the following doesn't seem to work:

((DrawingVisual)_children[_currentPointIndex]).SetValue(Canvas.LeftProperty, p.X);

If I need to animate the DrawingVisual's location, how do I properly do that Thanks!


Answer this question

Animate a DrawingVisual

  • shahapu

    I see. I was not considering what I need to do to be "drag and drop"...but I suppose it is! Thanks very much for the help.

  • odin88

    My point tranforms correclty now as I move the mouse. But when I click on the DrawingVisual to move it a second time it moves back to its original location as if it has lost the offset its transform accumulated with the previous move. Any ideas

  • Craig Doan

    Oh, so you're trying to do drag'n'drop. You have to store the visual's transformation at the begining of the dragging operation, and during the dragging set the transformation to be the composition of the stored transformation and the drag delta.

    I have created a simple sample here:
    http://www.valil.com/TestVisual.zip



  • mjohnson3091

    Visuals don't have support for layout so I think the only solution is to set the transform on them:

    DrawingVisual dv = new DrawingVisual();
    ...
    dv.Transform = new TranslateTransform(x,y);


  • Aravindtg

    That was the solution. Thanks!

  • Animate a DrawingVisual