How to specify path to Image resources in WPF application

我的梦境 提交于 2019-12-20 06:12:17

问题


Below is in a flow document
I can see all 5 in design
When I run the program then none are found
How can I get relative path to work?

<Paragraph>
    <Image Width="50" Height="50" Source="zHelpMain.png" Stretch="Fill"/>
</Paragraph>
<Paragraph>
    <Image Width="50" Height="50" Source="Images\VennIntersection.png" Stretch="Fill"/>
</Paragraph>
<Paragraph>
    <Image Width="50" Height="50" Source="/Gabe2a;component/Images/VennUnion.png" Stretch="Fill"/>
</Paragraph>
<Paragraph>
    <Image Width="50" Height="50" Source="/Images/helpMain.png" Stretch="Fill"/>
</Paragraph>
<Paragraph>
    <Image Width="50" Height="50" Source="images\helpMain.png" Stretch="Fill"/>
</Paragraph>


回答1:


Currently the image files are part of the solution, but not part of the project, so they're not embedded in the assembly when you compile. You need to add the to the Gabe2a project, with the build action set to "Resource".




回答2:


1). You have to add all Image files to your WPF project, for example, place them in Img directory; by default Build Action will be set to 'Resources'. Keep it intact.

2). Specify path to the image like:

Source="/[assembly name];component/Img/ImageFile

Pertinent to your particular case, the following syntax looks OK:

Source="/Gabe2a;component/Images/VennUnion.png"

Hope this will help. Best regards,



来源:https://stackoverflow.com/questions/27535374/how-to-specify-path-to-image-resources-in-wpf-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!