Search code examples
c#visual-studio-extensions

How to display images in a Visual Studio extension?


I am developing a Visual Studio extension. I need to display icons/images inside some tool window written with XAML.

I have put the images files inside the Resources folder inside the extension project folder. And I have declared the images like:

<Image Source="pack://application:,,,/Resources/Help_16.png" Width="16" Height="16" Margin="4,0,0,0"/>
<Image Source="pack://application:,,,/Resources/HowToFix_16.png" Width="16" Height="16" Margin="4,0,0,0"/>

They show nicely in the Visual Studio editor (XAML Designer) but the DON'T show anymore while running the Experimental Instance. No error reported in Visual Studio.

Why are they showing in the editor and NOT in the running instance? What am I missing? Thanks for your help!


Solution

  • Why are they showing in the editor and NOT in the running instance? What am I missing?

    Hard to say why defining image source in this format not work when debugging VSIX project though I can reproduce same issue on my side. Here's the command format which works for me:

    What's your project or actually assembly name? You can try the command in this format(The Source's value need to add/ProjectName;component so that it can display in experimental instance):

    <Image Source="pack://application:,,,/ProjectName;component/Resources/xxx.png" Width="16" Height="16" Margin="4,0,0,0"/>
    

    And then set the build action of these images to Resource, rebuild the project.

    It works in my machine with VS2017, hope it helps:)