【发布时间】:2020-04-01 10:21:54
【问题描述】:
我正在尝试在 WPF 中设置图像源,但相对 Uri 不起作用。
imgView.Source = new BitmapImage(new Uri("Res/Images/img.png", UriKind.Relative));
但这有效:
imgView.Source = new BitmapImage(new Uri("E:/C#/Folder/Project/Res/Images/img.png", UriKind.Absolute));
我应该在相对 Uri 中改变什么?
【问题讨论】:
-
将镜像文件的Build Action设置为Resource。然后使用完整的资源文件Pack URI:
imgView.Source = new BitmapImage(new Uri("pack://application:,,,/Res/Images/img.png")); -
谢谢,这可行