Canvas.SetLeft not working?

I'm trying to store the positions of all UI elements in a container. It seems to work fine. However, when I animate the UI elements and try to move them back to their original positions nothing happens. I am storing the position state like this :

Dictionary<string, Point> uiLocations = new Dictionary<string, Point>();

foreach (FrameworkElement element in this.Children)
{
if (!uiLocations.ContainsKey(element.Name))
{
uiLocations.Add(element.Name, new Point(Canvas.GetLeft(element), Canvas.GetTop(element)));
}
}

And after animating the elements to a different position I am attempting to restore the original locations like this:

foreach (FrameworkElement element in this.Children)
{
if (uiLocations.ContainsKey(element.Name))
{
Canvas.SetTop(element, uiLocations[element.Name].Y);
Canvas.SetLeft(element, uiLocations[element.Name].X);
}
}

Nothing happens, however. None of the elements change position. Any suggestions? I suppose I could use a TranslateTransform to get the elements to change position, but this seems rather combersome.

Any suggestions would be appreciated!

[1220 byte] By [JustinLearning] at [2007-12-27]
# 1

How are you animating the items?

Two culprits that come to mind are

animations that are 'held', basically animations that keep applying the last frame of the animation forever.

animating with RenderTransform which is independent of the layout position (ie final position = render transform applied after layout transform applied after layout position)

--Ifeanyi Echeruo [MSFT]

IfeanyiEcheruo at 2007-9-4 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified