图像显示在Visual Studio设计器中,但不会在运行时显示 [英] Image shows up in Visual Studio designer but not during run-time

查看:392
本文介绍了图像显示在Visual Studio设计器中,但不会在运行时显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用VS studio 2010,.NET 4.0。这是我的场景:

I'm currently working w/ VS studio 2010, .NET 4.0. Here is my scenario:

我目前有一个名为Images的类库项目,其中包含一个名为Icons的子文件夹。我的所有图标目前都存在于此项目中,并通过siteoforigin由多个项目访问。在设计师中,一切都很好,但在运行时,图像不会显示。

I currently have a class library project called "Images" that contains a sub folder called "Icons". All my icons currently live in this project and are accessed by multiple projects via siteoforigin. Everything shows up fine while in the designer, but during run time the images do not display.

这是我的文件夹结构:


  • 根文件夹

    • 图片

      • 图标

      所有项目都引用Images类lib。 proj,Images项目中icons子文件夹内的所有图标都设置为:Build Action = Resource。

      All projects are referencing the Images class lib. proj, and all icons inside the "icons" sub-folder within the "Images" project is set to: "Build Action = Resource".

      xaml看起来像这样(在设计时间内完全可见):

      The xaml looks like this (which is perfectly visible during design time):

           <Button Name="Button1" Click="Button1_Click">
              <Button.Content>
                  <Image Source="pack://siteoforigin:,,,/Data.Images;component/Icons/Button1.png" />
              </Button.Content>
          </Button>
      


      推荐答案

      siteoforigin 用于复制到可执行目录或子目录的文件,对于您应该使用 application 作为权限的资源,据我所知。

      siteoforigin is for files copied to the executable directory or subdirectories, for resources you should use application as authority as far as i know.

      SiteOfOrigin:


      路径:原始站点文件的名称,包括其相对于启动可执行程序集的位置的路径。

      Path: The name of the site of origin file, including its path relative to the location from which the executable assembly was launched.

      这篇关于图像显示在Visual Studio设计器中,但不会在运行时显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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