我有一個小應用程序,應該根據一些測試將圖像設置爲紅色或綠色。測試可能需要幾秒鐘,並且每個人都有一個自定義控件,並且圖像連接到它。當我點擊開始時,我想要完成第一個測試,通過改變那個圖像來顯示結果,然後繼續。但就目前而言,所有的測試都已經完成(可能是10秒),然後所有的燈都在同時改變。如何強制自定義控件在執行期間更新圖像?在執行期間重畫圖像WPF
private void start_Click(object sender, RoutedEventArgs e)
{
foreach (TestObject tObj in tObjList)
{
bool testResult = tObj.makeTest();
foreach (TestShower ts in m_TSList)
{
if (tObj == ts.gettObj())
{
if (testResult == true)
ts.setLightOn();
else
ts.setLightOff();
ts.UpdateLayout();
break;
}
}
}
}
public void setLightOn()
{
string strUri2 = String.Format(@"pack://application:,,,/;component/Images/Signal_On.png");
BitmapImage img = new BitmapImage(new Uri(strUri2));
iStatus.Source = null;
iStatus.Source = img;
}
public void setLightOff()
{
string strUri2 = String.Format(@"pack://application:,,,/;component/Images/Signal_Off.png");
BitmapImage img = new BitmapImage(new Uri(strUri2));
iStatus.Source = null;
iStatus.Source = img;
}
我會這樣做的!謝謝! – Nick3