我在WPF中具有图像控件(基本上是整个窗口(。当用户进行错误的输入时,我希望图像更改,然后甚至摇晃屏幕,等一下(使用thread.sleep(((,然后将图像更改回原始图像。<<<<<<<<
问题是:即使我在摇动屏幕之前更改了功能中的图像,在执行所有功能后,它仍然会更改。
我如何构成我的目标?
这是我尝试的:
//Change Diary Background
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.UriSource = new Uri(System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName) + @"libViewLoginViewLoginIncorrect.png");
bitmap.EndInit();
imgDiary.Source = bitmap;
Thread.Sleep(1000);
//Shake Screen
this.Left = this.Left - 20;
Thread.Sleep(50);
this.Left = this.Left + 20;
txtMasterKey.Focus();
,只有在完成所有操作之后,我的图像就会改变。图像示例
线程。
那是您的问题。
使您的方法异步。
用等待任务替换thread.sleep(n(。delay(n(。
其中n是您在那里的数字。