1 <!-- MatrixAnimationUsingPath.XAML
2 This example shows how to use PathGeometry and MatrixAnimationUsingPath to animate along a path. -->
4 <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
5 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
6 WindowTitle="MatrixAnimationUsingPath Example"
7 Background="{StaticResource MyGridBrushResource}">
10 <DockPanel Margin="20">
11 <Border Background="#99FFFFFF" BorderBrush="#CCCCFF" BorderThickness="2"
12 Margin="0,0,0,20" Padding="20" DockPanel.Dock="Top" >
13 <TextBlock Width="750">
14 This example animates an object (button) across the screen along a path. To do this, the Matrix value of the RenderTransform property is animated
15 along a PathGeometry. MatrixAnimationUsingPath is used to animate the matrix value.
19 <StackPanel DockPanel.Dock="Left">
20 <Canvas HorizontalAlignment="Left" Width="340" Height="240" >
22 <!-- This Path is only to show the path that the animated object will follow. -->
23 <Path VerticalAlignment="Top" Margin="15,15,15,15"
24 Data="M 10,100 C 35,0 135,0 160,100 180,190 285,200 310,100"
25 Stroke="Black" StrokeThickness="2"
28 <!-- The Button that is animated across the screen. -->
29 <Path Fill="Blue" Margin="0,0,15,15">
31 <RectangleGeometry x:Name="MyAnimatedRectGeometry" Rect="0,0 30 30" />
33 <Path.RenderTransform>
34 <MatrixTransform x:Name="myMatrixTransform">
35 <MatrixTransform.Matrix >
36 <Matrix OffsetX="10" OffsetY="100"/>
37 </MatrixTransform.Matrix>
39 </Path.RenderTransform>
43 <!-- Create a button to restart the animation. -->
44 <Button Width="300" HorizontalAlignment="Left" >
47 <!-- Trigger and StoryBoard to initiate the animation when the button is clicked. -->
49 <EventTrigger RoutedEvent="Button.Click">
53 <!-- Animates the button along the path. -->
54 <MatrixAnimationUsingPath
55 Storyboard.TargetName="myMatrixTransform"
56 Storyboard.TargetProperty="Matrix"
58 RepeatBehavior="Forever" AutoReverse="True" >
59 <MatrixAnimationUsingPath.PathGeometry>
60 <PathGeometry Figures="M 10,100 C 35,0 135,0 160,100 180,190 285,200 310,100" />
61 </MatrixAnimationUsingPath.PathGeometry>
62 </MatrixAnimationUsingPath>
69 <!-- This button starts an animation that follows the tangent
70 of the path because DoesRotateWithTangent is set to "True".-->
71 <Button Width="300" HorizontalAlignment="Left" >
72 Start Animation with DoesRotateWithTangent="True"
74 <!-- Trigger and StoryBoard to initiate the animation when the button is clicked. -->
76 <EventTrigger RoutedEvent="Button.Click">
80 <!-- Animates the button along the path following the tangent of the path. -->
81 <MatrixAnimationUsingPath
82 Storyboard.TargetName="myMatrixTransform"
83 Storyboard.TargetProperty="Matrix"
84 DoesRotateWithTangent="True"
86 RepeatBehavior="Forever" AutoReverse="True" >
87 <MatrixAnimationUsingPath.PathGeometry>
88 <PathGeometry Figures="M 10,100 C 35,0 135,0 160,100 180,190 285,200 310,100" />
89 </MatrixAnimationUsingPath.PathGeometry>
90 </MatrixAnimationUsingPath>
100 <!-- Displays functional code for demonstration. -->
101 <Border Background="#EEEEEE" BorderBrush="Black" BorderThickness="1">
102 <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
103 <TextBlock Style="{StaticResource CodeSnippetParagraph}" xml:space="preserve">
105 <!-- The Button that is animated across the screen. -->
106 <Button Margin="-30,0,0,0" MinWidth="100">Click
107 <Button.RenderTransform>
108 <MatrixTransform x:Name="myMatrixTransform">
109 <MatrixTransform.Matrix >
110 <Matrix OffsetX="10" OffsetY="100"/>
111 </MatrixTransform.Matrix>
112 </MatrixTransform>
113 </Button.RenderTransform>
116 <Span Foreground="Green"><!-- Animation with DoesRotateWithTangent set to false (default is false) --></Span>
118 <Bold><MatrixAnimationUsingPath
119 Storyboard.TargetName="myMatrixTransform"
120 Storyboard.TargetProperty="Matrix"
122 RepeatBehavior="Forever" AutoReverse="True" >
123 <MatrixAnimationUsingPath.PathGeometry>
124 <PathGeometry Figures="M 10,100 C 35,0 135,0 160,100 180,190 285,200 310,100" />
125 </MatrixAnimationUsingPath.PathGeometry>
126 </MatrixAnimationUsingPath>
130 <Span Foreground="Green"><!-- Animation with DoesRotateWithTangent --></Span>
132 <Bold><MatrixAnimationUsingPath
133 Storyboard.TargetName="myMatrixTransform"
134 Storyboard.TargetProperty="Matrix"
135 <Span Foreground="Red">DoesRotateWithTangent="True"</Span>
137 RepeatBehavior="Forever" AutoReverse="True" >
138 <MatrixAnimationUsingPath.PathGeometry>
139 <PathGeometry Figures="M 10,100 C 35,0 135,0 160,100 180,190 285,200 310,100" />
140 </MatrixAnimationUsingPath.PathGeometry>
141 </MatrixAnimationUsingPath>
148 <!-- End of Display Canvas -->