gpt4 book ai didi

c# - 当我启动项目时,图像不加载

转载 作者:行者123 更新时间:2023-11-30 22:06:29 24 4
gpt4 key购买 nike

我将图像添加到窗口,但当我启动项目时图像未加载。

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.

最佳答案

确保图像被复制到输出文件夹。在 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

关于c# - 当我启动项目时,图像不加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23660671/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com