How to move a rectangle by pressing a button? I tried this XAML code, but I get an InvalidOperationException:

Cannot resolve all property references in the Canvas.Top property path. Check that the corresponding objects support such properties.

<Canvas> <Rectangle Canvas.Top="200" Name="redRectangle" Canvas.Left="200" Fill="Red" Stroke="Blue" MinHeight="50" MinWidth="50"></Rectangle> <Button Canvas.Top="250" Canvas.Left="10" >move left <Button.Triggers> <EventTrigger RoutedEvent="Button.Click"> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="redRectangle" From="200" To="50" Duration="0:0:5" Storyboard.TargetProperty="Canvas.Top"> </DoubleAnimation> </Storyboard> </BeginStoryboard> </EventTrigger> </Button.Triggers> </Button> </Canvas> 

    1 answer 1

    Try this:

     Storyboard.TargetProperty="(Canvas.Top)" 

    This must be the correct syntax for attached property.

    • Indeed, the problem was precisely in this. I rewrote the code, everything turned out. Many thanks! - david_I
    • @david_I: Please! - VladD