At design time pack uri is valid, but not at runtime?

后端 未结 4 1419
暖寄归人
暖寄归人 2021-02-13 19:00

I\'m setting a Button\'s content to an Image. It looks something like this:

4条回答
  •  北荒
    北荒 (楼主)
    2021-02-13 19:54

    Just to shine a light on what was happening in your situation. The second pack uri. The one that worked. Is meant for resources located in an assembly other than the host application. By the sounds of it, the host application was loading this resource from the Class Library in question?

    You can see the differences in the pack uri schemes here: MSDN Pack URI Scheme

    The uri changes slightly when referencing a resource from the main assembly, and referencing one from another assembly.

    Also, the pack://application:,,, includes what is referred to as the "authority", to omit it would basically make it a relative path, both are valid in most cases where the application authority is assumed.

    EDIT: basically because /Subfolder/Resource.xaml(.jpg etc.) and /Assembly;component/Resource.xaml are very similar, the latter tells the parser/loader that it's looking in a referenced assembly, not in the main application's assembly. (I imagine this helps speed up the search).

提交回复
热议问题