如何在 Visual Studio 扩展中显示图像? [英] How to display images in a Visual Studio extension?

查看:77
本文介绍了如何在 Visual Studio 扩展中显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 Visual Studio 扩展.我需要在一些用 XAML 编写的工具窗口中显示图标/图像.

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

我已将图像文件放在扩展项目文件夹内的 Resources 文件夹中.我已经声明图像如下:

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"/>

它们在 Visual Studio 编辑器(XAML 设计器)中显示得很好,但在运行实验实例时不再显示.Visual Studio 中未报告错误.

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!

推荐答案

为什么它们显示在编辑器中而不显示在正在运行的实例中?我错过了什么?

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

很难说为什么在调试 VSIX 项目时以这种格式定义图像源不起作用,尽管我可以在我这边重现相同的问题.这是对我有用的命令格式:

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:

您的项目或实际程序集名称是什么?你可以试试这个格式的命令(Source的值需要加上/ProjectName;component才能在实验实例中显示):

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"/>

然后将这些图片的build action设置为Resource,重建工程.

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

它在我的 VS2017 机器上工作,希望它有帮助:)

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

这篇关于如何在 Visual Studio 扩展中显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆