0

我有一个应用程序可以循环播放从我的游戏中截取的屏幕截图。我当前的解决方案适用于第一张图像,但在我循环图像后它不会刷新。我的 PropertyChanged 事件已配置并且运行良好。只有图像不起作用。

我的显示代码是:

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

然后我后面的代码检索绝对 Uri 并通过绑定进行设置。

我怎样才能让这个工作?

4

2 回答 2

1

我不相信类会触发 ;UriSourceBitmapImage重新加载/重新渲染ImageImage.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

更改后面的代码以返回 BitmapImage 而不是 Uri 可以解决此问题。

这意味着 XAML 应更改为:

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