WPF Animation

From no name for this wiki
Revision as of 17:08, 5 February 2010 by Claude (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Media.Animation;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();                      
                     
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            DoubleAnimation oLabelAngleAnimation = new DoubleAnimation(); 
            oLabelAngleAnimation.From = 0; 
            oLabelAngleAnimation.To = 360; 
            oLabelAngleAnimation.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 500)); 
            oLabelAngleAnimation.RepeatBehavior = new RepeatBehavior(4); 
            RotateTransform oTransform = (RotateTransform) this.rectangle1.RenderTransform; 
            oTransform.BeginAnimation(RotateTransform.AngleProperty, oLabelAngleAnimation); 
        }
       
     
    }
}

Xaml:

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300"
    > 
    <Grid>
        <Rectangle Margin="48,78,90,127" 
                   Name="rectangle1" 
                   Stroke="Black" >
            <Rectangle.RenderTransform>
                <RotateTransform Angle="0"  CenterX="95"  CenterY="20" />
            </Rectangle.RenderTransform>
        </Rectangle>
        <Button Height="23" HorizontalAlignment="Right" Margin="0,0,41,59" Name="button1" VerticalAlignment="Bottom" Width="75" Click="button1_Click">Button</Button>
    </Grid>
</Window>