Absolute UriSource of a Resource image

2019-02-26 01:17发布

I have a WPF project. If I store image in {ProjectRoot}\Images\image.png, and compile it as Resource then I can access it from a xaml (this xaml is located at Root) as BitmapImage by BitmapImage UriSource="Images/image.png". But if I move the xaml to another folder, say {ProjectRoot}\Xamls, now I have to use BitmapImage UriSource="../Images/image.png". Is there a way to specify an absolute project path, so that I can refer to them with the same path regardless of the location of the xaml?

标签: .net wpf xaml uri
2条回答
萌系小妹纸
2楼-- · 2019-02-26 01:57

Take a look at Pack URIs in WPF

查看更多
beautiful°
3楼-- · 2019-02-26 02:07

You can use this syntax both to reference by an absolute path inside the same project, or reference files in other projects:

UriSource="/MyAssemblyName;component/Images/image.png"

Here "MyAssemblyName" is the project/dll/exe name and "component" indicates the project root.

查看更多
登录 后发表回答