I need help with the XAML code: I have a polygon that is constantly moving along a certain path:

<Canvas > <Path Stroke="LightBlue" Data="{StaticResource pathg}" Canvas.Top="10" Canvas.Left="10" /> <Polygon Name="polygon1" Stroke="Yellow" Fill="Yellow" Points="-100,150 -80,140 -80,120 -35,150 -80,180 -80,160 "> <Polygon.Triggers> <EventTrigger RoutedEvent="Window.Loaded"> <BeginStoryboard> <Storyboard> <DoubleAnimationUsingPath Storyboard.TargetProperty="(Canvas.Top)" Duration="0:0:15" RepeatBehavior="Forever" PathGeometry="{StaticResource pathg}" Source="Y" > </DoubleAnimationUsingPath> <DoubleAnimationUsingPath Storyboard.TargetProperty="(Canvas.Left)" Duration="0:0:15" RepeatBehavior="Forever" PathGeometry="{StaticResource pathg}" Source="X" > </DoubleAnimationUsingPath> </Storyboard> </BeginStoryboard> </EventTrigger> </Polygon.Triggers> </Polygon> </Canvas> 

What needs to be added and where, so that when you hover the cursor on the landfill, it stops (the movement stopped), and when you move the cursor away, keep moving

    1 answer 1

    Name the BeginStoryboard object:

     <BeginStoryboard Name="Storyboard"> 

    Then add two additional triggers to the Polygon.Triggers section:

     <EventTrigger RoutedEvent="Mouse.MouseEnter"> <PauseStoryboard BeginStoryboardName="Storyboard" /> </EventTrigger> <EventTrigger RoutedEvent="Mouse.MouseLeave"> <ResumeStoryboard BeginStoryboardName="Storyboard" /> </EventTrigger>