0

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.

  1. Does this mean that I am not allowed to manipulate attached properties in such animation scenarios?
  2. In case I am not allowed, how I am supposed to manipulate Grid.Left and Grid.Top for a child element?
Themelis
  • 4,048
  • 2
  • 21
  • 45
  • 1
    Check [this](https://stackoverflow.com/questions/9048226/animating-wpf-element-in-xaml-using-attached-property). Attached properties have different syntax – Eldar Nov 26 '19 at 16:42
  • Damn and I tried to search about it and couldn't find that. Thanks @Eldar! – Themelis Nov 26 '19 at 16:43

0 Answers0