2014-05-14 76 views
2

我向窗口添加图像,并且当我启动项目时图像不加载。当我开始项目时,图像不加载

XAML代码:

<Window x:Class="WpfApplication3.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="350" Width="525"> 
    <Grid> 
     <Image HorizontalAlignment="Left" Height="188" Margin="88,64,0,0" VerticalAlignment="Top" Width="288"> 
      <Image.Source> 
       <BitmapImage UriSource="image1.png"/> 
      </Image.Source> 
     </Image> 
     <Rectangle Fill="#FF2424C7" HorizontalAlignment="Left" Height="100" Margin="338,24,0,0" Stroke="Black" VerticalAlignment="Top" Width="125"/> 
    </Grid> 
</Window> 

我可以看到在Visual Studio设计的图像:

Screenshot of visual studio showing that the image is shown in designer.


的图像文件存在于解决方案目录:

Screenshot of Windows Explorer showing that the file exists in the solution directory.

+2

执行目录中是否存在'image1.png'? – tnw

+0

你是如何添加图像资源的?松散的文件?你把他们包括在项目中了吗? – Tuco

+0

是的,它在文件夹中。 – user3637574

回答

3

确保图像正被复制到输出文件夹。在Visual Studio中(我只有2010作为参考),查看图像文件的属性并确保Copy to Output Directory设置为“Copy if newer”。

Screenshot of Visual Studio 2010 properties window showing the 'Copy to Output Directory' property.

您可以检查是否图像被通过查看bin目录复制。这应该是您的项目目录下的bin\Debugbin\Release

+0

我有视觉工作室终极2013年,但我没有像你这样的属性中的这个选项。你知道解决它的其他方法吗?或我在哪里可以找到这个选项?坦克 – user3637574

相关问题