当前位置:首页 > Windows程序 > 正文

WPF中的image控件的Source赋值

2021-03-28 Windows程序

image控件的Source设置为相对路径后(Source="haha.png")运行不能显示

解决方案:当Source设置为相对路径后(Source="haha.png")Visual Studio 2013会在属性栏的Source中生成“/WpfApplication1;component/haha.png”。

不知道在其他Visual Studio中会不会这样,但是可以按照这样写就不会出现不能显示的问题。

img.Source = new BitmapImage(new Uri("pack://application:,,,/Images/haha.jpg"));
//或
img.Source = new BitmapImage(new Uri("pack://SiteOfOrigin:,,,/image/haha.jpg"));

WPF中的image控件的Source赋值

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/69091.html