【发布时间】:2013-04-03 23:11:38
【问题描述】:
我已经在这个问题上苦苦挣扎了很长一段时间,在 SO 和 Google 上到处寻找,但没有成功。
我想在一些简单的窗口中显示背景图片(多么雄心勃勃!)
<Window x:Class="HelloWorld_Lite.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None" ResizeMode="NoResize"
Title="Hello World" Height="350" Width="525">
<Window.Background >
<ImageBrush ImageSource="HelloWorld-Lite;component/Background.jpg" />
</Window.Background>
<Grid>
<Label Content="Hello World!" Height="28" HorizontalAlignment="Left" Margin="225,30,0,0" Name="label2" VerticalAlignment="Top" />
</Grid>
</Window>
图像已添加到项目中(添加 > 现有项)并构建为“资源”
我进行了清理和重建,但这件事仍然让我很紧张。
请告诉我我遗漏了一些明显的东西
编辑:将文件保存为 PNG 格式解决了问题(?)。 PNG 大小 = 2Mb,JPG 大小 = 360k。
如果这是一个限制,那就太荒谬了。
编辑 2 :将原始 JPG 从 1280x853 调整为 480x320 也解决了这个问题。
因此,它看起来像是 JPG 格式特有的大小限制。
【问题讨论】:
-
文件是否位于文件夹中?在我的情况下,当我在 Images 文件夹中为我的图像创建 uri 时,这有效“/ApplicationModule;component/Images/Device-Print-icon-16.png”
-
文件位于项目根目录/HelloWorld-Lite