I have a Rectangle
isnide a Canvas
and I want to move it from the top left corner to the bottom right one, using the framework's animations. I chose to use DoubleAnimation
in order to manipulate the Grid.Left
and Grid.Top
properties of the rectangle, as seen bellow,
<Rectangle Name="MyRectangle"
Width="100"
Height="100"
Fill="Blue"
Canvas.Left="0"
Canvas.Top="0">
<Rectangle.Triggers>
<EventTrigger RoutedEvent="Rectangle.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="MyRectangle"
Storyboard.TargetProperty="Canvas.Left"
From="0"
To="690"
Duration="0:0:5"
AutoReverse="True"
RepeatBehavior="Forever" />
<DoubleAnimation Storyboard.TargetName="MyRectangle"
Storyboard.TargetProperty="Canvas.Top"
From="0"
To="340"
Duration="0:0:5"
AutoReverse="True"
RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Rectangle.Triggers>
</Rectangle>
Unfortunately, when I run the application I get a runtime exception stating that,
Cannot resolve all property references in the property path 'Canvas.Left'. Verify that applicable objects support the properties.
- Does this mean that I am not allowed to manipulate attached properties in such animation scenarios?
- In case I am not allowed, how I am supposed to manipulate
Grid.Left
andGrid.Top
for a child element?