简体   繁体   English

如何在 Visual Studio 扩展中显示图像?

[英]How to display images in a Visual Studio extension?

I am developing a Visual Studio extension.我正在开发 Visual Studio 扩展。 I need to display icons/images inside some tool window written with XAML.我需要在一些用 XAML 编写的工具窗口中显示图标/图像。

I have put the images files inside the Resources folder inside the extension project folder.我已将图像文件放在扩展项目文件夹内的 Resources 文件夹中。 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.它们在 Visual Studio 编辑器(XAML 设计器)中显示得很好,但在运行实验实例时不再显示。 No error reported in Visual Studio. Visual Studio 中没有报告错误。

Why are they showing in the editor and NOT in the running instance?为什么它们显示在编辑器中而不是在正在运行的实例中? What am I missing?我错过了什么? Thanks for your help!谢谢你的帮助!

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.很难说为什么在调试 VSIX 项目时以这种格式定义图像源不起作用,尽管我可以在我这边重现相同的问题。 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):您可以尝试这种格式的命令( Source的值需要添加/ProjectName;component以便它可以在实验实例中显示):

<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.然后将这些镜像的build action设置为Resource ,重新build action项目。

It works in my machine with VS2017, hope it helps:)它在我的机器上使用 VS2017 工作,希望它有帮助:)

Refer to MSDN .请参阅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我试图在资源文件夹中放置一个图像,并将构建操作设置为资源,并且我在这样的 xmal 文件中声明

 <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.将“ReferencedAssembly”更改为您当前的 vsix 项目名称,然后重建项目,对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM