Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7554705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:24:35+00:00 2026-05-30T11:24:35+00:00

I would like to move the circle by clicking the buttons. For Example; There

  • 0

I would like to move the circle by clicking the buttons. For Example;

There is circle on the position of (0,0) and I would like to move it by clicking on X+ button. This will increase X one by one without stopping and circle move on the X position. Then when I click on the Y+ button, It will increase Y just 20 times and the circle start the move on Y axis as well.

I have one code, but I couldn’t move it dynamically. It moves to predefined position.

XAML:

 <Window x:Class="circle_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" Loaded="Window_Loaded" Closed="Window_Closed" >
<Canvas>
    <Ellipse Width="10" Height="10" Canvas.Left="0" Canvas.Top="0" Fill="Black" x:Name="el" />
    <Button Canvas.Left="255" Canvas.Top="266" Content="Move On X" Height="23"  Width="75" Click="Button_Click" />
    <Button Canvas.Left="139" Canvas.Top="272" Content="Move On Y+" Height="23" Name="button1" Width="75" Click="Button2_Click" />
</Canvas>

CODE:

    public int X;
    public int Y;

    public bool inside = true;


    private void Window_Loaded(object sender, RoutedEventArgs e)
    {


        if (inside)
        {

            DoubleAnimation animatex = new DoubleAnimation();

            animatex.To = X;
            el.BeginAnimation(Canvas.LeftProperty, animatex);

            DoubleAnimation animatey = new DoubleAnimation();
            animatey.To = Y;

            el.BeginAnimation(Canvas.TopProperty, animatey);

        }  
    } 


    public void Button_Click(object sender, RoutedEventArgs e)
    {

        if (inside)
        {
            X++;
        }
    }

    public void Button2_Click(object sender, RoutedEventArgs e)
    {

        Y = Y + 20;
    }

This was my idea to move it dynamically, but it doesnt work. Can you help me, please ? Where do I do wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:24:37+00:00Added an answer on May 30, 2026 at 11:24 am

    You are confusing a few things here.

    First, an animation won’t run forever just because you do not set its duration. Instead the default duration of a DoubleAnimation is 1 second, then it stops.

    Second, the animation’s To property won’t magically change just because you change the variable that you assigned it to beforehand. Changes to the animation`s properties would be ignored anyway after it has been started.

    I think using animations is the wrong approach to solving your problem. What you want to achieve (a continuously moving object with changeable speed vector) is perhaps best done by utilizing a DispatcherTimer and cyclically updating the object’s position according to the elapsed time.

    The following sample code may give you an idea about how this works. You can now change the speed vector however you like (by setting speed.X and speed.Y by some button clicks), and the object will move accordingly. A possible optimization would be not to start the timer immediately, but only when the vector becomes non-zero, and stop it again when speed becomes zero.

    private DispatcherTimer timer = new DispatcherTimer(); // timer object
    private Vector speed = new Vector(0, 0); // movement in pixels/second, initially zero
    
    public MainWindow()
    {
        InitializeComponent();
    
        timer.Interval = TimeSpan.FromMilliseconds(50); // update 20 times/second
        timer.Tick += TimerTick;
        timer.Start();
    }
    
    private void TimerTick(object sender, EventArgs e)
    {
        // movement in one interval
        double dx = speed.X * timer.Interval.TotalSeconds;
        double dy = speed.Y * timer.Interval.TotalSeconds;
        // update position
        Canvas.SetLeft(el, Canvas.GetLeft(el) + dx);
        Canvas.SetTop(el, Canvas.GetTop(el) + dy);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to move one DIV element inside another. For example, I want
I would like to move a file or folder from one place to another
I would like to move old records from a table to another one. If
I would like to move an animated UIImage across the screen. How is this
I would like to draw a simple circle and move it to the defined
I would like to move data back and fourth between clojure applications. Application settings
I would like to move some files around in Visual Studio. But I see
I would like to move an imageView contained on a cell and it works
Our team would like to move from the Visual SourceSafe (VSS) to the Team
I have two XmlDocuments and I would like to move an XmlNode selected from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.