简体   繁体   中英

WPF c# displaying a image for a short period of time

I am trying to create a project where I have a picture button and once the user clicks on it the picture changes to something else.

But once it changes I want that picture to go away and go back to the original before it was clicked.

I am stuck at the point to create that "timer" for the second picture to show. Also the second picture that shows up is a random picture from 2 other pictures. So it needs to change pictures randomly after every button click.

Once idea that comes to mind is that you could try to use a BackgroundWorker implementation.

Click on Picture:

  • Change the image to whatever you want
  • Start the background worker

Background Worker Implementation:

  • Thread.Join() for however long you want it keep that image
  • return when done

Background Worker Task Completed:

  • Set the image back to the original picture

It's not the true intent of the BackgroundWorker, but it will probably solve the problem you are trying to get around (not tying up the UI thread).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM