Simple Ball moving animation in wpf

Leave a Comment
Here we will show you create complete animation idea in wpf application. Here you can see that we provide you code snippets for it.

MainWindow
<Window x:Class="Animation.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Canvas>
        <Ellipse Height="50" Width="50" Fill="red" Name="animationobject" Canvas.Top="20" Canvas.Left="20" />
    </Canvas>
</Window>
MainWindow.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Animation
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            DoubleAnimation annimation = new DoubleAnimation();
            annimation.From = 0;
            annimation.To = 450;
            annimation.Duration = new Duration(TimeSpan.Parse("0:0:3"));
            annimation.AutoReverse = true;
            annimation.RepeatBehavior = new RepeatBehavior(TimeSpan.Parse("0:0:18"));
            animationobject.BeginAnimation(Canvas.LeftProperty,annimation);
        }
    }
}
See the output of this demo but it is not looking animated in snap but we are providing you source code also just download and run it.



0 comments:

Post a Comment