2012-02-10 64 views
-1

需要更新WPF圖像框中的圖像。我正在考慮創建一個包含所有路徑的列表,然後使用一個定時器控件檢查10秒鐘。 10秒鐘過後,從列表中選擇下一個ID並綁定到圖像框。我是WPF的新手。任何人都可以通過一個實例來幫助我。在WPF圖像框中每10秒後更改圖像

+0

你已經知道該怎麼做多少?你有哪些麻煩? – 2012-02-10 10:47:10

+0

我已經完成了將單個圖像綁定到圖像框的操作。 – user1107875 2012-02-10 11:19:56

回答

0

使用DispatcherTimer在常規intervalls中調用方法。在這種方法中改變綁定圖像,記得提高INotifyPropertyChanged事件讓WPF知道它應該再次查詢綁定屬性。

+0

嗨,感謝您的回覆,但通過使用Timer_Elapsed()事件。下面的代碼放置在失效的事件。 Action action =()=> BindToImages(lststr); Dispatcher.BeginInvoke(action); _timer.Start(); – user1107875 2012-02-13 08:40:38

0

嗨,我已經使thig與下面的代碼運行。

private void timer_Elapsed(object sender,System.Timers.ElapsedEventArgs e) 
    { 

     Action action1 =() => this.BeginStoryboard((Storyboard)this.FindResource("BlinkStoryboardFed")); 
     Dispatcher.BeginInvoke(action1); 
     Action action =() => BindToImages(lststr); 
     Dispatcher.BeginInvoke(action); 
     //BindToImages(lststr); 
     _timer.Start(); 
    } 

public void BindToImages(List<string> lststrpath) 
    { 
     lock (_locker) 
     { 
      for (int i = 0; i < lststrpath.Count; i++) 
      { 
       if (count == 0) 
       { 
        startindex = i; 
        this.BindToImgIndx = startindex; 
        AppState.Index = i; 
        BitmapImage img = new BitmapImage(); 
        img.BeginInit(); 
        img.UriSource = new Uri(lststrpath[startindex].ToString(), UriKind.Relative); 
        img.CacheOption = BitmapCacheOption.OnLoad; 
        img.EndInit(); 
        image1.Source = img; 
        count++; 
       } 
       else 
       { 
        int k = AppState.Index; 
        k = ++k; 
        this.BindToImgIndx = startindex; 
        if (k < lststrpath.Count) 
        { 
         BitmapImage img = new BitmapImage(); 
         img.BeginInit(); 
         img.UriSource = new Uri(lststrpath[k].ToString(), UriKind.Relative); 
         img.CacheOption = BitmapCacheOption.OnLoad; 
         img.EndInit(); 
         image1.Source = img; 
        } 
        AppState.Index = k; 
       } 
       this.BeginStoryboard((Storyboard)this.FindResource("BlinkStoryboardUnFed")); 
       break; 
      } 
     } 
    } 
+0

這不回答這個問題。如果您有共享的信息,您應該編輯您的問題。請閱讀http://stackoverflow.com/faq上的常見問題解答 – vidstige 2012-02-13 08:48:22