2013-02-28 77 views
0

我有一個應用程序,可以循環播放來自我的遊戲的屏幕截圖。我目前的解決方案適用於第一個圖像,但是在我循環圖像後,它不會令人耳目一新。我的PropertyChanged事件已配置並正常運行。只有圖像無法正常工作。在圖像組件中顯示來自光盤的圖像

我顯示的代碼是:

<Image DataContext="{StaticResource IMG}" Stretch="UniformToFill"> 
    <Image.Source> 
     <BitmapImage UriSource="{Binding Image}"/> 
    </Image.Source> 
</Image> 

,然後我後面的代碼檢索絕對URI,並通過綁定設置。

我該如何得到這個工作?

回答

1

我不相信UriSource上的BitmapImage類會觸發重新加載/重新渲染的Image; Image.Source但是:

void Main() 
{ 
    var firstUri= new Uri("http://www.gravatar.com/avatar/2e8b6a4ea2ee8aedc49e5e4299661543?s=128&d=identicon&r=PG"); 
    var secondUri= new Uri("http://www.gravatar.com/avatar/23333db13ce939b8a70fb36dbfd8f934?s=32&d=identicon&r=PG"); 

    var wnd = new Window(); 
    var pnl = new StackPanel(); 
    wnd.Content = pnl; 

    var img = new Image() 
    { 
     Source = new BitmapImage(firstUri), 
     Stretch = Stretch.UniformToFill, 
    }; 
    wnd.Show(); 
    pnl.Children.Add(img); 

    // Optional; just need something to change the img src 
    Observable 
     .Timer(TimeSpan.FromSeconds(2)) 
     // The next line is roughly equivalent to invoking on 
     // the Dispatcher (i.e., marshalling back to the UI thread) 
     .ObserveOn(new DispatcherScheduler(wnd.Dispatcher)) 
     .Subscribe(_ => 
     { 
      img.Source = new BitmapImage(secondUri); 
     }); 
} 
+0

是的,謝謝,我貼我得到了什麼工作作爲另一個答案。如果我創建一個新的BitmapImage,並在我的代碼中返回它,它會起作用。感謝您指點我正確的方向! – Runewake2 2013-02-28 05:46:28

0

更改後面的代碼以返回BitmapImage而不是Uri可解決此問題。

這意味着XAML應改爲:

<Image DataContext="{StaticResource IMG}" Stretch="UniformToFill" Source="{Binding Image}" /> 
相關問題