将图像分配给Image.Source

时间:2011-03-31 06:38:34

标签: wpf

如何分配图片Image.Source:Image.Source =“Images \ 1.bmp” - 不起作用(你不能分配图片)

3 个答案:

答案 0 :(得分:1)

Image myImage3 = new Image();
BitmapImage bi3 = new BitmapImage();
bi3.BeginInit();
bi3.UriSource = new Uri("smiley_stackpanel.PNG", UriKind.Relative);
bi3.EndInit();
myImage3.Stretch = Stretch.Fill;
myImage3.Source = bi3;

As mentioned above easily found here

答案 1 :(得分:0)

请参阅Pack URIs in WPF

不要忘记将“1.bmp”的构建操作设置为“资源”

答案 2 :(得分:0)

MSDN http://msdn.microsoft.com/en-us/library/system.windows.controls.image.source.aspx的Image.Source页面有一个例子。您需要分配ImageSource,而不是字符串。 (但当然可以在上面的文章中看到Pack URI)

相关问题