有时候会在代码中更换image的source,正确的设置方式为:
//从运行目录的子文件夹中的资源文件获取
Uri uri = new Uri("pack://application:,,,/images/btn_close.png");
//从资源文件中获取
Uri uri = new Uri("pack://application:,,,/ReferencedAssembly;component/btn_close.png");
BitmapImage bitmap = new BitmapImage(uri);
//为Source属性赋值
CloseWindow.Source = bitmap;
本文介绍在WPF应用程序中如何正确地更改Image控件的源代码,包括从运行目录子文件夹和资源文件中获取图片的方法。通过使用Uri和BitmapImage类,可以实现Image控件的动态图片加载。
698

被折叠的 条评论
为什么被折叠?



