1 <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3 Title="Interpolation Methods"
5 x:Class="InterpolationMethods.Page1"
8 <TabControl MinHeight="500" MaxHeight="700" MinWidth="400">
9 <TabItem Style="{StaticResource TabStyle}" Header="Interpolation Methods Sample" IsSelected="true">
11 <TextBlock Style="{StaticResource HeaderStyle}">Interpolation Methods Sample</TextBlock>
13 <TextBlock Style="{StaticResource mainContentStyle}">This example demonstrates different methods of moving between two keyframes in an animation.</TextBlock>
18 <TabItem Name="xaml" Style="{StaticResource TabStyle}" Header="XAML">
21 <TextBlock Name="xamlCheck" Style="{StaticResource CodeSnippetParagraph}" xml:space="preserve">
22 <![CDATA[<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" Margin="20">
23 <Canvas Width="600" Height="300">
25 <!-- Mark the key frame points for illustrative purposes. -->
27 Style="{StaticResource MyMarkerRectangleStyle}"
28 Canvas.Left="10" Canvas.Top="50" />
29 <TextBlock Canvas.Left="10">Starting Value</TextBlock>
32 Style="{StaticResource MyMarkerRectangleStyle}"
33 Canvas.Left="500" Canvas.Top="50" />
35 <TextBlock Canvas.Left="500">1. Value = 500 <LineBreak /> KeyTime = 0:0:7</TextBlock>
36 <Rectangle Style="{StaticResource MyMarkerRectangleStyle}"
37 Canvas.Left="200" Canvas.Top="50"/>
38 <TextBlock Canvas.Left="200">2. Value = 200 <LineBreak /> KeyTime = 0:0:10</TextBlock>
39 <Rectangle Style="{StaticResource MyMarkerRectangleStyle}"
40 Canvas.Left="350" Canvas.Top="50" />
41 <TextBlock Canvas.Left="350">3. Value = 350 <LineBreak /> KeyTime = 0:0:15</TextBlock>
44 <!-- This rectangle is animated using a key frame animation
45 with linear interpolation. -->
46 <Rectangle Name="linearKeyFrameRectangle"
54 <SolidColorBrush Color="Blue" Opacity="0.4" />
58 <!-- This rectangle is animated using a key frame animation
59 with splined interpolation. -->
60 <Rectangle Name="splineKeyFrameRectangle"
68 <SolidColorBrush Color="Purple" Opacity="0.4" />
72 <!-- This rectangle is animated using a key frame animation
73 with discrete interpolation. -->
74 <Rectangle Name="discreteKeyFrameRectangle"
82 <SolidColorBrush Color="Lime" Opacity="0.4" />
86 <!-- This rectangle is animated using a key frame animation
87 with a combination of interpolation methods. -->
88 <Rectangle Name="combinationKeyFrameRectangle"
96 <SolidColorBrush Color="Orange" Opacity="0.4" />
107 <!-- These buttons are used to restart, pause, resume, and stop the animations. -->
108 <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
109 <StackPanel.Triggers>
110 <EventTrigger SourceName="restartButton"
111 RoutedEvent="Button.Click">
112 <BeginStoryboard Name="myBeginStoryboard">
114 <!-- Animates the position of a Rectangle from a base value of 10
115 to 500, 200, and then 350 using linear interpolation. -->
116 <DoubleAnimationUsingKeyFrames
117 Storyboard.TargetName="linearKeyFrameRectangle" Storyboard.TargetProperty="(Canvas.Left)"
118 Duration="0:0:15" FillBehavior="HoldEnd">
119 <DoubleAnimationUsingKeyFrames.KeyFrames>
120 <LinearDoubleKeyFrame Value="500" KeyTime="0:0:7" />
121 <LinearDoubleKeyFrame Value="200" KeyTime="0:0:10" />
122 <LinearDoubleKeyFrame Value="350" KeyTime="0:0:15" />
123 </DoubleAnimationUsingKeyFrames.KeyFrames>
124 </DoubleAnimationUsingKeyFrames>
126 <!-- Animates the position of a Rectangle from a base value of 10
127 to 500, 200, and then 350 using splined interpolation. -->
128 <DoubleAnimationUsingKeyFrames Storyboard.TargetName="splineKeyFrameRectangle" Storyboard.TargetProperty="(Canvas.Left)"
129 Duration="0:0:15" FillBehavior="HoldEnd">
130 <DoubleAnimationUsingKeyFrames.KeyFrames>
131 <SplineDoubleKeyFrame Value="500" KeyTime="0:0:7" KeySpline="0.25,0.5 0.75,1" /><!--IB: was 7.5-->
132 <SplineDoubleKeyFrame Value="200" KeyTime="0:0:10" KeySpline="0.25,0.5 0.75,1" />
133 <SplineDoubleKeyFrame Value="350" KeyTime="0:0:15" KeySpline="0.25,0.5 0.75,1" />
134 </DoubleAnimationUsingKeyFrames.KeyFrames>
135 </DoubleAnimationUsingKeyFrames>
137 <!-- Animates the position of a Rectangle from a base value of 10
138 to 500, 200, and then 350 using discrete interpolation. -->
139 <DoubleAnimationUsingKeyFrames Storyboard.TargetName="discreteKeyFrameRectangle" Storyboard.TargetProperty="(Canvas.Left)" Duration="0:0:15" FillBehavior="HoldEnd">
140 <DoubleAnimationUsingKeyFrames.KeyFrames>
141 <DiscreteDoubleKeyFrame Value="500" KeyTime="0:0:7" />
142 <DiscreteDoubleKeyFrame Value="200" KeyTime="0:0:10" />
143 <DiscreteDoubleKeyFrame Value="350" KeyTime="0:0:15" />
144 </DoubleAnimationUsingKeyFrames.KeyFrames>
145 </DoubleAnimationUsingKeyFrames>
147 <!-- Animates the position of a Rectangle from a base value of 10
148 to 500, 200, and then 350 using a variety of interpolation methods. -->
149 <DoubleAnimationUsingKeyFrames
150 Storyboard.TargetName="combinationKeyFrameRectangle"
151 Storyboard.TargetProperty="(Canvas.Left)" Duration="0:0:15" FillBehavior="HoldEnd">
152 <DoubleAnimationUsingKeyFrames.KeyFrames>
153 <DiscreteDoubleKeyFrame Value="500" KeyTime="0:0:7" />
154 <LinearDoubleKeyFrame Value="200" KeyTime="0:0:10" />
155 <SplineDoubleKeyFrame Value="350" KeyTime="0:0:15" KeySpline="0.25,0.5 0.75,1" />
156 </DoubleAnimationUsingKeyFrames.KeyFrames>
157 </DoubleAnimationUsingKeyFrames>
164 SourceName="pauseButton"
165 RoutedEvent="Button.Click">
166 <PauseStoryboard BeginStoryboardName="myBeginStoryboard" />
169 SourceName="resumeButton"
170 RoutedEvent="Button.Click">
171 <ResumeStoryboard BeginStoryboardName="myBeginStoryboard" />
174 SourceName="skipToEndButton"
175 RoutedEvent="Button.Click">
176 <SkipStoryboardToFill BeginStoryboardName="myBeginStoryboard" />
179 SourceName="stopButton"
180 RoutedEvent="Button.Click">
181 <StopStoryboard BeginStoryboardName="myBeginStoryboard" />
183 </StackPanel.Triggers>
185 <Button Name="restartButton">Restart</Button>
186 <Button Name="pauseButton">Pause</Button>
187 <Button Name="resumeButton">Resume</Button>
188 <Button Name="skipToEndButton">Skip To End</Button>
189 <Button Name="stopButton">Stop</Button>
196 <TabItem Name="xamlcsharp" Style="{StaticResource TabStyle}" Header="XAML + C#">
197 <TabControl TabStripPlacement="Right">
198 <TabItem Name="xcsharpCheck" Style="{StaticResource TabStyle2}" Header="XAML"></TabItem>
199 <TabItem Style="{StaticResource TabStyle2}" Header="C#"></TabItem>
203 <TabItem Name="xamlvb" Style="{StaticResource TabStyle}" Header="XAML + Visual Basic.NET">
204 <TabControl TabStripPlacement="Right">
205 <TabItem Name="xvbCheck" Style="{StaticResource TabStyle2}" Header="XAML"></TabItem>
206 <TabItem Style="{StaticResource TabStyle2}" Header="VB.NET"></TabItem>
210 <TabItem Name="csharp" Style="{StaticResource TabStyle}" Header="C#"></TabItem>
212 <TabItem Name="vb" Style="{StaticResource TabStyle}" Header="Visual Basic.NET"></TabItem>
214 <TabItem Name="managedcpp" Style="{StaticResource TabStyle}" Header="Managed C++"></TabItem>
216 <TabItem Style="{StaticResource TabStyle}" Header="Preview Sample">
217 <!-- Demonstrates the DoubleAnimationUsingKeyFrames class. DoubleAnimationUsingKeyFrames objects are
218 used to animate the position of rectangles across a canvas. -->
221 <Style x:Key="MyMarkerRectangleStyle">
222 <Setter Property="Rectangle.Height" Value="230"/>
223 <Setter Property="Rectangle.Width" Value="50"/>
224 <Setter Property="Rectangle.Fill">
226 <SolidColorBrush Color="Gray" Opacity="0.25" />
231 <StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" Margin="20">
232 <Canvas Width="600" Height="300">
234 <!-- Mark the key frame points for illustrative purposes. -->
236 Style="{StaticResource MyMarkerRectangleStyle}"
237 Canvas.Left="10" Canvas.Top="50" />
238 <TextBlock Canvas.Left="10">Starting Value</TextBlock>
241 Style="{StaticResource MyMarkerRectangleStyle}"
242 Canvas.Left="500" Canvas.Top="50" />
244 <TextBlock Canvas.Left="500">1. Value = 500 <LineBreak /> KeyTime = 0:0:7</TextBlock>
245 <Rectangle Style="{StaticResource MyMarkerRectangleStyle}"
246 Canvas.Left="200" Canvas.Top="50"/>
247 <TextBlock Canvas.Left="200">2. Value = 200 <LineBreak /> KeyTime = 0:0:10</TextBlock>
248 <Rectangle Style="{StaticResource MyMarkerRectangleStyle}"
249 Canvas.Left="350" Canvas.Top="50" />
250 <TextBlock Canvas.Left="350">3. Value = 350 <LineBreak /> KeyTime = 0:0:15</TextBlock>
253 <!-- This rectangle is animated using a key frame animation
254 with linear interpolation. -->
255 <Rectangle Name="linearKeyFrameRectangle"
263 <SolidColorBrush Color="Blue" Opacity="0.4" />
267 <!-- This rectangle is animated using a key frame animation
268 with splined interpolation. -->
269 <Rectangle Name="splineKeyFrameRectangle"
277 <SolidColorBrush Color="Purple" Opacity="0.4" />
281 <!-- This rectangle is animated using a key frame animation
282 with discrete interpolation. -->
283 <Rectangle Name="discreteKeyFrameRectangle"
291 <SolidColorBrush Color="Lime" Opacity="0.4" />
295 <!-- This rectangle is animated using a key frame animation
296 with a combination of interpolation methods. -->
297 <Rectangle Name="combinationKeyFrameRectangle"
305 <SolidColorBrush Color="Orange" Opacity="0.4" />
316 <!-- These buttons are used to restart, pause, resume, and stop the animations. -->
317 <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
318 <StackPanel.Triggers>
319 <EventTrigger SourceName="restartButton"
320 RoutedEvent="Button.Click">
321 <BeginStoryboard Name="myBeginStoryboard">
323 <!-- Animates the position of a Rectangle from a base value of 10
324 to 500, 200, and then 350 using linear interpolation. -->
325 <DoubleAnimationUsingKeyFrames
326 Storyboard.TargetName="linearKeyFrameRectangle" Storyboard.TargetProperty="(Canvas.Left)"
327 Duration="0:0:15" FillBehavior="HoldEnd">
328 <DoubleAnimationUsingKeyFrames.KeyFrames>
329 <LinearDoubleKeyFrame Value="500" KeyTime="0:0:7" />
330 <LinearDoubleKeyFrame Value="200" KeyTime="0:0:10" />
331 <LinearDoubleKeyFrame Value="350" KeyTime="0:0:15" />
332 </DoubleAnimationUsingKeyFrames.KeyFrames>
333 </DoubleAnimationUsingKeyFrames>
335 <!-- Animates the position of a Rectangle from a base value of 10
336 to 500, 200, and then 350 using splined interpolation. -->
337 <DoubleAnimationUsingKeyFrames Storyboard.TargetName="splineKeyFrameRectangle" Storyboard.TargetProperty="(Canvas.Left)"
338 Duration="0:0:15" FillBehavior="HoldEnd">
339 <DoubleAnimationUsingKeyFrames.KeyFrames>
340 <SplineDoubleKeyFrame Value="500" KeyTime="0:0:7" KeySpline="0.25,0.5 0.75,1" />
341 <SplineDoubleKeyFrame Value="200" KeyTime="0:0:10" KeySpline="0.25,0.5 0.75,1" />
342 <SplineDoubleKeyFrame Value="350" KeyTime="0:0:15" KeySpline="0.25,0.5 0.75,1" />
343 </DoubleAnimationUsingKeyFrames.KeyFrames>
344 </DoubleAnimationUsingKeyFrames>
346 <!-- Animates the position of a Rectangle from a base value of 10
347 to 500, 200, and then 350 using discrete interpolation. -->
348 <DoubleAnimationUsingKeyFrames
349 Storyboard.TargetName="discreteKeyFrameRectangle"
350 Storyboard.TargetProperty="(Canvas.Left)" Duration="0:0:15" FillBehavior="HoldEnd">
351 <DoubleAnimationUsingKeyFrames.KeyFrames>
352 <DiscreteDoubleKeyFrame Value="500" KeyTime="0:0:7" />
353 <DiscreteDoubleKeyFrame Value="200" KeyTime="0:0:10" />
354 <DiscreteDoubleKeyFrame Value="350" KeyTime="0:0:15" />
355 </DoubleAnimationUsingKeyFrames.KeyFrames>
356 </DoubleAnimationUsingKeyFrames>
358 <!-- Animates the position of a Rectangle from a base value of 10
359 to 500, 200, and then 350 using a variety of interpolation methods. -->
360 <DoubleAnimationUsingKeyFrames
361 Storyboard.TargetName="combinationKeyFrameRectangle"
362 Storyboard.TargetProperty="(Canvas.Left)" Duration="0:0:15" FillBehavior="HoldEnd">
363 <DoubleAnimationUsingKeyFrames.KeyFrames>
364 <DiscreteDoubleKeyFrame Value="500" KeyTime="0:0:7" />
365 <LinearDoubleKeyFrame Value="200" KeyTime="0:0:10" />
366 <SplineDoubleKeyFrame Value="350" KeyTime="0:0:15" KeySpline="0.25,0.5 0.75,1" />
367 </DoubleAnimationUsingKeyFrames.KeyFrames>
368 </DoubleAnimationUsingKeyFrames>
376 SourceName="pauseButton"
377 RoutedEvent="Button.Click">
378 <PauseStoryboard BeginStoryboardName="myBeginStoryboard" />
381 SourceName="resumeButton"
382 RoutedEvent="Button.Click">
383 <ResumeStoryboard BeginStoryboardName="myBeginStoryboard" />
386 SourceName="skipToEndButton"
387 RoutedEvent="Button.Click">
388 <SkipStoryboardToFill BeginStoryboardName="myBeginStoryboard" />
391 SourceName="stopButton"
392 RoutedEvent="Button.Click">
393 <StopStoryboard BeginStoryboardName="myBeginStoryboard" />
395 </StackPanel.Triggers>
397 <Button Name="restartButton">Restart</Button>
398 <Button Name="pauseButton">Pause</Button>
399 <Button Name="resumeButton">Resume</Button>
400 <Button Name="skipToEndButton">Skip To End</Button>
401 <Button Name="stopButton">Stop</Button>