Click here to Skip to main content
15,908,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!

Please help me, I am newcomer in WPF. I first created two ellipse objects using code:
//first ellipse object
Ellipse myElp1=new Ellipse;
myElp1.Width=10;
myElp1.Height=10;
myElp1.Fill=Brushes.Blue;

//second ellipse object
Ellipse myElp2=new Ellipse;
myElp2.Width=10;
myElp2.Height=10;
myElp2.Fill=Brushes.Blue;

Now, i placed these two objects on canvas with id/name myCanvas at different positions using:

TranslateTransform mytransform=new TranslateTransform(100,100);
myElp1.RenderTransform=mytransform;
myCanvas.Children.Add(myElp1);

//now, place second ellipse

//delay(1000); //for delaying

TranslateTransform mytransform=new TranslateTransform(200,200);
myElp1.RenderTransform=mytransform;
myCanvas.Children.Add(myElp2);

It works good....Now i want that the second ellipse object appear on canvas after one second delay. For this, uncomment delay()method in above code. Its definition is as:

void delay(double ms)
{
DateTime m=DateTime.Now.AddMilliseconds(ms);
do
{
;
}
while(DateTime.Now<=m)
}

but i am failed to achieve the required result...I was supposing that the second ellipse will appear on the screen after one second but failed to achieve this..my screen waited for one second and then it display two ellipse simultaneously. If i use MessageBox()instead of delay method it works good but i dont want MessageBox that prompt the user to clik so that my program display second ellipse.
Posted

1 solution

This is because everything is on the same UI thread. Basically, the rendering of the first can't take place until after the delay, which then immediately displays the second.

What you need to do is create a Storyboard and have it animate the Opacity of the second one from 0 to 1 over the duration you require.

This will then handle the stuff for you.

BTW, if you don't want a smooth transition from 0 to 1, then you can you can set a BeginTime and make the duration much shorter.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900