Source: Problems with resource paths in WPF
? Problems with resource paths in WPF
1. Referencing resources for the current project (note that the build action for Xxxx.png should be set to Resource or embedded Resource)
[CSharp]? View Plaincopy
- <imagebrush? imagesource="/currentassemblyname;component/subfoldername/xxxx.png"/>??
?
2. Reference to resources of other projects? (Note that the build action for Xxxx.png should be set to Resource or embedded Resource)
[HTML]? View Plaincopy
- <ImageBrush?ImageSource="pack://application:,,,/otherassemblyname;component/subfolder/xxx.png"/>??
?
3. Referencing resources under relative paths (note it is best to set the copy to Output directory property of Xxx.png to always copy)
[HTML]? View Plaincopy
- <ImageBrush?ImageSource="Pack://siteoforigin:,,,./subfolder/xxx.png?"/>??
?
4. Reference a resource under an absolute path?
[HTML]? View Plaincopy
- <ImageBrush?ImageSource="C:\test\xxx.png"/>??
?
5. When using the path of the pack prefix, if the following error occurs:System.UriFormatException:Invalid uri:invalid Port specified, and the pack path you are using does not have an error. This is because pack://scheme is not registered and there are two solutions:
A.?????? Instantiates a System.Windows.Application that is called PackUriHelper class during instantiation
[CSharp]? View Plaincopy
- if ? (! Uriparser.isknownscheme ("pack"))???
- {??
- ???????? New ? System.Windows.Application ();???
- }??
?
B.????? Call once System.IO.Packaging.PackUriHelper.UriSchemePack????
[CSharp]? View Plaincopy
- string ? s?=? System.IO.Packaging.PackUriHelper.UriSchemePack;?
Problems with resource paths in WPF