IronPython 和 WPF。如何在代码运行时更改 Image.Source?

IronPython & WPF. How to change Image.Source at runtime in code?

如果我有一个 XAML 元素:

<Image x:Name="img"  Source= "D:\test.gif" />

我需要:

self.img.Source = ?

C# 逻辑没有帮助。

许多方法之一是从 Uri 创建 BitmapImage:

from System import Uri
from System.Windows.Media.Imaging import BitmapImage

uri = Uri("D:\test.gif")
self.img.Source = BitmapImage(uri)