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 6723811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:36:49+00:00 2026-05-26T09:36:49+00:00

I have a rectangle which want to move using Canvas.SetLeft(rect, x); But I wanna

  • 0

I have a rectangle which want to move using Canvas.SetLeft(rect, x);

But I wanna make it look like a smooth transition (animation). Here’s the code snippet that’s supposed to do this:

void animate()
    {
        for (int a = 0; a < 10; a++)
        {
            MainWindow.current.Dispatcher.BeginInvoke(new Action(move));
            x += 10;
            Thread.Sleep(100);
        }
    }

    void move()
    {
        Canvas.SetLeft(rect, x);
    }

It seems very basic but I’m having trouble doing it. I want the thread to sleep for a little time, & then set the rectangle’s x to a new value. But instead, the thread sleeps for 30*10 milli seconds, then the rectangle moves right instantly by 10*10 units. I’m not able to get the animation effect I want. And I’m aware that I’ve called Sleep on the GUI thread but I don’t think that should affect the animation.

  • 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-26T09:36:49+00:00Added an answer on May 26, 2026 at 9:36 am

    Instead of forcing your UI thread to sleep. I would suggest you to use the Storyboard Animation provided by WPF specially for this purpose. This link will get you started if its’s something new too you –

    http://vbcity.com/blogs/xtab/archive/2009/12/28/wpf-simple-animations-to-move-and-resize-elements-simultaneously.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to fill a region using Graphics.fillRoundRect(), but I want a rectangle in
I have a list of Rectangle shapes which I keep in memory, I want
I want to have a rectangle which has three different colors in flex. I
I have an abstract base class called Shape from which both Circle and Rectangle
I have a rectangle that I've created and set its individual properties like so
I have two points (a line segment) and a rectangle. I would like to
I am new to iphone Programming . I have a rectangle on which i
Imagine I have a rectangle say 400px x 300px. Then let’s say I want
I have GUI created using netbeans GUI builder. I want to add there an
I have an array of points PArr [0..3] which correspond to the rectangle points

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.