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

后端 未结 4 1424
暖寄归人
暖寄归人 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:45

    Whelp, I figured it out...kinda.

    I copied that xaml code from one project where the output type is Windows Application, to another project where the output type is Class Library.

    I didn't think of it at the time, but apparently when the output type is a Class Library the pack URI needs to change.

    So instead of "pack://application:,,,/NavigationImages/nav_up_left.png" I changed it to "/ProjectName;component/NavigationImages/nav_up_left.png" and now it's working just fine.

    I'm not 100% clear why this is works and not the former. I've read through the MSDN documentation on pack URIs in WPF but perhaps I misinterpreted something.

    I'll leave this answer unchecked in the event someone can give me a good explanation why what I previously had doesn't work in a project with output type Class Library.

    I'm probably missing something really simple. @_@

提交回复
热议问题