What is application's site of origin and when

2020-03-01 05:03发布

  • What is application's site of origin
  • When to use it
  • How is the build action of a resource file associated with it
  • What is the difference between pack://application:,,, and pack://siteoforigin:,,,

2条回答
爱情/是我丢掉的垃圾
2楼-- · 2020-03-01 06:06

The site of origin is the location (i.e. the physical folder) of the application executable assembly (i.e. the .exe that the user runs). The URI is thus relative to that folder.

Example: You have

  • C:\Programs\MyApp\MyApp.exe
  • C:\Programs\MyApp\MyIcon.bmp
  • C:\Programs\MyApp\Icons\MyOtherIcon.bmp

The pack URIs are pack://siteoforigin:,,,/MyIcon.bmp and pack://siteoforigin:,,,/Icons/MyOtherIcon.bmp when running the MyApp.exe. That means you have to copy those files to those places.

In contrast, the application pack URI refers to resources embedded in your assembly (by using Build Action "Resource").

查看更多
Evening l夕情丶
3楼-- · 2020-03-01 06:06

If you do not want to be bound by the restrictions of having your application resources declared at compile time, there is another option for you. No, this doesn't involve using fully qualified Uris to reference resources over the internet. Although, that is indeed supported. WPF provides you with an abstraction for the application's conceptual site of origin i.e. the location from where the application was deployed. For instance, if your application was launched from http://nerddawg.blogspot.com , then your application's site of origin is http://nerddawg.blogspot.com . To access an image at images/AuntDahlia.gif at that location, you would specify in markup:

<Image Source="pack://siteoforigin:,,,/images/AuntDahlia.jpg" />

for more

http://nerddawg.blogspot.com/2005/11/resources-in-windows-presentation.html

查看更多
登录 后发表回答