1

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!

Stephane
  • 333
  • 1
  • 13

2 Answers2

2

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:)

LoLance
  • 25,666
  • 1
  • 39
  • 73
  • Hi Lance! Thanks for your reply! I changed the build action for the images and rebuilt. Not sure what the component name should be. Could you be more specific please? On my side, I could get the the assembly name. But my Resources folder is right inside the project folder and I wonder what the component name should be. BTW, when I add /ProjectName before the resource folder in the declaration, I get a tooltip saying: "Could not locate resource '/ProjectName/Resources/xxx.png'". Not getting this when removing the first "/". However still don't know what to put for component name. Any idea? – Stephane Aug 19 '19 at 10:02
  • No need to change it. Just use `component`, assuming your xx.png is in Resources folder, and Resources folder is directly in Project folder. We don't need to create a component folder, the component is part of the string. All you need to change I think is the ProjectName if your xx.png is in resources folder. – LoLance Aug 19 '19 at 10:07
1

Refer to MSDN. I tried to put an image inside the Resources folder,and set build action to Resource, And I declared in xmal file like this

 <Image Source="pack://application:,,,/ReferencedAssembly;component/Resources/image.png"/>

change the "ReferencedAssembly" to your current vsix project name,then rebuild the project,works for me.

Dasheen
  • 56
  • 2