我知道这是一个简单的问题,但我无法弄清楚或在任何地方找到答案。我只是试图在运行时使用C#在WPF中更改图像源。每当代码运行时,它只会删除1.gif,并有一个空白的白框,而不是显示2.gif。提前致谢。wpf更改图片源
XAML:
<Image x:Name="img" Height="150" Margin="142,20,138,0" VerticalAlignment="Top">
<Image.Source>
<BitmapImage UriSource="C:\Users\John\1.gif" />
</Image.Source>
</Image>
C#:
string sUri = @"C:\Users\John\2.gif";
Uri src = new Uri(sUri, UriKind.RelativeOrAbsolute);
BitmapImage bmp = new BitmapImage(src);
img.Source = bmp;
'高度'设置,但'宽度'伸展以适应新的'图像'? – Yogesh 2009-11-16 06:02:08