Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
swdev:dotnet:wpf:control_transforms_and_animations [2010/12/10 16:30]
smayr [Examples]
swdev:dotnet:wpf:control_transforms_and_animations [2010/12/10 16:31] (current)
smayr [Animations]
Line 71: Line 71:
 anim.DecelerationRatio = .33; anim.DecelerationRatio = .33;
 btnSearch.BeginAnimation(Button.WidthProperty, anim); btnSearch.BeginAnimation(Button.WidthProperty, anim);
 +</code>
 +
 +**Other Examples**
 +
 +XAML:
 +<code xml>
 +<Canvas>
 +    <!--Geometrical Figures-->
 +    <Ellipse  Name="shapeEllipse" Width="50" Height="50" Fill ="Gold" />
 +    <Polygon Name="shapeTriangle"
 +        Points="300,200 400,125 400,275 300,200"
 +        Stroke="Purple" 
 +        StrokeThickness="2">
 +        <Polygon.Fill>
 +            <SolidColorBrush Color="Blue" Opacity="0.4"/>
 +        </Polygon.Fill>
 +    </Polygon>
 +
 +    <!--Controls-->
 +    <Button Name="btnAnimate" Width="100" Height="30" Canvas.Bottom="5" Click="btnAnimate_Click" >Animate</Button>
 +</Canvas>
 +</code>
 +
 +C#:
 +<code csharp>
 +private void btnAnimate_Click(object sender, RoutedEventArgs e)
 +{
 +    AnimateEllipse();
 +    AnimateTriangle();
 +}
 +
 +private void AnimateEllipse()
 +{
 +    TranslateTransform tt = new TranslateTransform(0, 0);
 +
 +    DoubleAnimation daX = new DoubleAnimation(100,
 +            new Duration(TimeSpan.FromMilliseconds(500)) 
 +        );
 +
 +    DoubleAnimation daY = new DoubleAnimation(50,
 +            new Duration(TimeSpan.FromMilliseconds(500)) 
 +        );
 +
 +    tt.BeginAnimation(TranslateTransform.XProperty, daX);
 +    tt.BeginAnimation(TranslateTransform.YProperty, daY);
 +
 +    shapeEllipse.RenderTransform = tt;
 +}
 +
 +private void AnimateTriangle()
 +{
 +    // Scale Transform
 +    ScaleTransform scaletrans = new ScaleTransform();
 +    scaletrans.ScaleX = -1;
 +    //scaletrans.CenterX = 0.25;
 +    shapeTriangle.LayoutTransform = scaletrans;
 +
 +    // Translate Transform
 +    TranslateTransform tt = new TranslateTransform(100, 0);
 +    shapeTriangle.RenderTransform = tt;
 +}
 </code> </code>