0

ゲームから取得したスクリーンショットを循環するアプリがあります。私の現在のソリューションは最初の画像で機能しますが、画像を循環させた後は更新されません。PropertyChanged イベントが構成され、正常に実行されています。画像だけが機能していません。

表示するための私のコードは次のとおりです。

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

次に、私のコード ビハインドは絶対 Uri を取得し、バインディングを介して設定されます。

どうすればこれを機能させることができますか?

4

2 に答える 2

1

クラスがのリロード/再レンダリングをトリガーするとUriSourceは思わない; ただし、動作します:BitmapImageImageImage.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);
        });
}
于 2013-02-28T05:43:05.187 に答える
0

Uri の代わりに BitmapImage を返すようにコード ビハインドを変更すると、この問題が解決します。

これは、XAML を次のように変更する必要があることを意味します。

<Image DataContext="{StaticResource IMG}" Stretch="UniformToFill" Source="{Binding Image}" />
于 2013-02-28T05:44:46.927 に答える