有时候会在代码中更换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;