Wpf Absolute vs. Relative Pack URIs

前端 未结 3 1296
梦谈多话
梦谈多话 2020-12-30 14:45

My question is: Am I reading MSDN wrong OR is MSDN wrong? I am trying to reference an image Resource via relative URI.

The MSDN page titled

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-30 15:16

    The reason, when running as a separate assembly, that your Relative Pack URI must begin with ../ or no leading backslash is because of how relative URIs are used, from MSDN (emphasis mine):

    Absolute vs. Relative Pack URIs

    ...

    If a leading backslash is used, however, the relative pack URI reference is then considered relative to the root of the application.

    Therefore if you'd like the images to remain relative to your referenced assembly, simply omit the leading slash or use ../ if in a sub-folder.

    See the image below for an example of how this looks at runtime:

    Absolute vs. Relative Pack URIs

提交回复
热议问题